我正在使用 CSS3 构建随机形状。我被困在这个蛋形上。我检查了蛋形的数学,它由 2 个不同半径的圆组成。然而,我无法将此基本结构与此处的 CSS 构建代码联系起来,尤其是“border-radius”部分。
#egg {
display:block;
background-color:green;
width:126px;
/* width has to be 70% of height */
/* could use width:70%; in a square container */
height:180px;
/* beware that Safari needs actual px for border radius (bug) */
-webkit-border-radius:63px 63px 63px 63px / 108px 108px 72px 72px;
/* fails in Safari, but overwrites in Chrome */
border-radius:50% 50% 50% 50%/60% 60% 40% 40%;
}
最佳答案
5.1. Curve Radii: the ‘border-radius’ properties
The two length or percentage values of the ‘border-*-radius’ properties define the radii of a quarter ellipse that defines the shape of the corner of the outer border edge (see the diagram below). The first value is the horizontal radius, the second the vertical radius. If the second value is omitted it is copied from the first. If either length is zero, the corner is square, not rounded. Percentages for the horizontal radius refer to the width of the border box, whereas percentages for the vertical radius refer to the height of the border box. Negative values are not allowed.
border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
.egg {
display: block;
width: 120px;
height: 180px;
background-color: green;
border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
}
<div class="egg"></div>
Further reading在边界半径上使用斜杠语法。
关于html - CSS3 Border-radius 创建一个蛋形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18796538/