Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS3 Border-radius to create an egg shape

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;
  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%;
}
like image 236
user2567757 Avatar asked Sep 13 '13 23:09

user2567757


People also ask

How do you make an oval shape in CSS?

All you have to do is to change border-radius: 40px to border-radius: 50% .

How do you put a radius on a border in CSS?

CSS Syntaxborder-radius: 1-4 length|% / 1-4 length|%|initial|inherit; Note: The four values for each radius are given in the order top-left, top-right, bottom-right, bottom-left. If bottom-left is omitted it is the same as top-right. If bottom-right is omitted it is the same as top-left.

What CSS3 property creates rounded borders?

The border-radius CSS property rounds the corners of an element's outer border edge. You can set a single radius to make circular corners, or two radii to make elliptical corners.


1 Answers

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%;

enter image description here

.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.

like image 50
Josh Crozier Avatar answered Sep 19 '22 15:09

Josh Crozier