Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I make an ellipse using the CSS border-radius property?

I'm trying to make a rectangular image (headshot)

width: 200px;   
height: 280px; 

display as an ellipse.

I can't seem to stop it trying to make a circle, or forming points at top and bottom, while the sides are still flat.

Any help appreciated!

like image 706
Luke Hargraves Avatar asked Oct 13 '16 10:10

Luke Hargraves


People also ask

How do you make an ellipse shape in CSS?

To create an ellipse first we will create a simple rectangle of our desired height and width. Approach To create Rectangle: In order to create an ellipse of our desired size, we will create a div in HTML and will give it a class named as an ellipse.

How do you make a border oval in CSS?

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

How do you draw a border-radius with an oval?

You add the HTML element. But instead of assigning it an equal width and height, set them to be different. Then, set the CSS border-radius property to 50%. The result is an oval.


2 Answers

As per the specification, the individual border-radius properties accept a second value which if not specified defaults to whatever the first value is.

3.3 The 'border-radius' properties

The two length values of the 'border-radius' properties define the radii of a quarter ellipse that defines the shape of the corner (see the diagram below). The first value is the horizontal radius (or vertical if the 'writing-mode' is vertical). If the second length is omitted it is equal to the first (and the corner is thus a quarter circle). If either length is zero, the corner is square, not rounded. The border radius also causes the element's background to be rounded (even if the border is 'none'). Negative values are not allowed.

Image from the specification

You can use this to specify exactly where you want the radius to occur:

div {
  background: red;
  width: 200px;   
  height: 280px; 
  border-bottom-left-radius: 50% 25%;
  border-bottom-right-radius: 50% 25%;
  border-top-left-radius: 50% 25%;
  border-top-right-radius: 50% 25%;
}
<div></div>

An ellipse would use 100% for either the first or second value, but a value less than 100% for the other:

div {
  background: red;
  width: 200px;   
  height: 280px; 
  border-bottom-left-radius: 25% 100%;
  border-bottom-right-radius: 25% 100%;
  border-top-left-radius: 25% 100%;
  border-top-right-radius: 25% 100%;
}
<div></div>
like image 98
James Donnelly Avatar answered Sep 21 '22 09:09

James Donnelly


Have you really tryed something ??

#test {
  width: 200px;
  height: 280px;
  border: 1px solid;
  border-radius: 50%;
}
<div id='test'></div>
like image 27
Steeve Pitis Avatar answered Sep 20 '22 09:09

Steeve Pitis