简体   繁体   English

CSS3 Border-radius 创建一个鸡蛋形状

[英]CSS3 Border-radius to create an egg shape

I am using CSS3 to build up random shapes.我正在使用 CSS3 来构建随机形状。 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.然而,我无法将这个基本结构与此处的 CSS 构建代码联系起来,尤其是“边界半径”部分。

#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. 5.1. Curve Radii: the 'border-radius' properties 曲线半径:'border-radius' 属性

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). 'border-*-radius' 属性的两个长度或百分比值定义了四分之一椭圆的半径,该半径定义了外边框边角的形状(见下图)。 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.使用斜杠语法进一步阅读边界半径。

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.您可以通过在顶部具有较大的垂直半径和在底部具有较小的垂直半径来创建鸡蛋形状。

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.第二个值用于垂直半径,因此曲线下降到元素高度的 60%。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM