This is the CSS:
div {
width: 0;
height: 0;
border: 180px solid red;
border-radius: 180px;
}
How does it produce the circle below?
Suppose, if a rectangle width is 180 pixels and height is 180 pixels then it would appear like this:
After applying border-radius 30 pixels it would appear like this:
The rectangle is becoming smaller, that is, almost going to disappear if the radius size increases.
So, how does a border of 180 pixels with height/width-> 0px
become a circle with a radius of 180 pixels?
Best Answer
Let's reformulate that into two questions:
Where do
width
andheight
actually apply?Let's have a look at the areas of a typical box (source):
The
height
andwidth
apply only on content, if the correct box model is being used (no quirks mode, no old Internet Explorer).Where does
border-radius
apply?The
border-radius
applies on the border-edge. If there is neither padding nor border it will directly affect your content edge, which results in your third example.What does this mean for our border-radius/circle?
This means that your CSS rules result in a box that only consists of a border. Your rules state that this border should have a maximum width of 180 pixels on every side, while on the other hand it should have a maximum radius of the same size:
In the picture, the actual content of your element (the little black dot) is really non-existent. If you didn't apply any
border-radius
you would end up with the green box. Theborder-radius
gives you the blue circle.It gets easier to understand if you apply the
border-radius
only to two corners:Since in your example the size and radius for all corners/borders are equal you get a circle.
Further resources
References
Demonstrations
border-radius
affects the border (think of the inner blue box as the content box, the inner black border as the padding border, the empty space as the padding and the giant red border as the, well, border). Intersections between the inner box and the red border would usually affect the content edge.