HH123_3 2022-09-28 10:11 采纳率: 86.8%
浏览 46
已结题

学习前端遇到的问题6: 这两段关于border-radius的设置有什么不同呢?

学习前端遇到的问题6: 这两段关于border-radius的设置有什么不同呢?

div {
  width: 200px;
  height: 200px;
  background: #fb3;
  margin-bottom: 20px;
  
}
.test-1 {
  border-radius: 50% 50% 0 0 / 100%;
}

.test-2 {
  border-radius: 50% 50% 0 0 / 100% 100% 0 0;
}

结果

img

第一个设置border-radius: 50% 50% 0 0 / 100%;为下面设置的一个缩写

border-top-left-radius: 50% 100%;
border-top-right-radius: 50% 100%;
border-bottom-right-radius: 0px 100%;
border-bottom-left-radius: 0px 100%;

第二个设置border-radius: 50% 50% 0 0 / 100% 100% 0 0;为下面设置的一个缩写

border-top-left-radius: 50% 100%;
border-top-right-radius: 50% 100%;
border-bottom-right-radius: 0px 0px;
border-bottom-left-radius: 0px 0px;

两者不同的在于:

border-bottom-right-radius: 0px 100%;
border-bottom-left-radius: 0px 100%;


border-bottom-right-radius: 0px 0px;
border-bottom-left-radius: 0px 0px;

这两者产生的效果的难道不是一样的么?为什么最后的效果不一样呢?

  • 写回答

3条回答 默认 最新

  • MAXLZ 2022-09-28 12:11
    关注

    这是个很有意思的问题,仔细往下看,你会发现其实这个问题并不简单。

    W3C中对border-radius的标准描述中有这样一段话:

    Corner curves must not overlap: When the sum of any two adjacent border radii exceeds the size of the border box, UAs must proportionally reduce the used values of all border radii until none of them overlap. The algorithm for reducing radii is as follows:

    大致意思就是,如果两个相邻圆角的半径之和超出边框长度时,UA必须按比例减少所有边界半径的值,直到它们都不重叠。

    半径缩放算法如下:

    f=min(Li/Si),其中i∈{top, right, bottom, left},Si是i边的圆角半径之和,Ltop = Lbottom = box width,Lleft = Lright = box height。如果f<1,将所有角的半径乘以f进行缩小。

    对于第一个border-radius: 50% 50% 0 0 / 100%;。f为0.5(因为left边的相邻两个圆角半径和为200%,两个相邻圆角半径都是100%,所以f为0.5),将每个圆角半径乘以0.5,实际渲染的圆角半径为border-radius: 25% 25% 0 0 / 50%;

    而对于第二个border-radius: 50% 50% 0 0 / 100% 100% 0 0。计算f为1,所以不会将圆角半径进行缩小。

    最后附上w3c关于border-radius的标准描述:https://www.w3.org/TR/2021/CRD-css-backgrounds-3-20210726/#corner-overlap

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 10月6日
  • 已采纳回答 9月28日
  • 创建了问题 9月28日

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来