Is it possible to make a capsule shape using border-radius without a set width or height?
I want the left and right sides to be completely rounded while the capsule would remain straight along it's horizontal length. Setting the radius to 50% doesn't seem to give the desired affect.
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.
The only difference between them is the right button has a radius of 5px applied. As with borders, radius allows you to set different properties for each side of the element using the toggle controls.
The border-top-right-radius property is used to round the top right corner of an element. The property takes in one or two values that define the radii of a quarter ellipse that defines the shape of the corner of the outer border edge (see the diagram below).
Applying a very large border radius seems to work on many browsers (IE9+, FF, Chrome) like this mod of David's fiddle http://jsfiddle.net/cthQW/1/
border-radius: 500px;
Yes, this is possible (albeit I've only tested in Chromium 28/Ubuntu 12.10):
div { /* this is the only relevant part: */ border-radius: 20%/50%; /* this is irrelevant, and just so the element can be visualised/displayed: */ width: 50%; height: 5em; margin: 2em auto; background-color: #000; }
JS Fiddle demo.
The important information is, obviously, the 20%/50%
property-value; the 20%
is the 'horizontal length' of the radius, whereas the 50%
is the 'vertical length'; using two different measurements gives an elliptical curve to the border, instead of a single measurement, which yields the more circular radius. Obviously this requires a certain amount of adjustment to your own requirements
References:
border-radius
(at Mozilla Developer Network).If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With