问题
I am using CSS3 to build up random shapes. I am stuck on this Egg Shape. I checked upon the mathematics of Egg Shapes, which are composed by 2 circles with different radius. Yet I can't link this fundamental construction with the CSS buildup code here, especially the "border-radius" part.
#egg {
display:block;
width:126px;
/* width has to be 70% of height */
/* could use width:70%; in a square container */
height:180px;
background-color:green;
/* 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%;
}
回答1:
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 on border radius with slash syntax.
回答2:
Per specification on the border radius
If values are given before and after the slash, then the values before the slash set the horizontal radius and the values after the slash set the vertical radius.
You create the egg shape by having a larger vertical radius at the top and a smaller vertical radius at the bottom.
回答3:
Your border radius is broken down into:
border-bottom-left-radius: 50% 40%;
border-bottom-right-radius: 50% 40%;
border-top-left-radius: 50% 60%;
border-top-right-radius: 50% 60%;
Let's break down the top-left one further:
- The first value is horizontal radius, it means the border is rounded up to half the width.
- The second value is for vertical radius, so the curve goes down to 60% of the element's height.
来源:https://stackoverflow.com/questions/18796538/explain-the-usage-of-css3-in-an-egg-shape