Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make an oval in css?

I want to make an oval like:

enter image description here

But when i used this code:

<!DOCTYPE html> <html>     <head>         <meta http-equiv="Content-Type" content="text/html"; charset="utf-8" />         <title>Oval</title>         <style type="text/css">             .oval {                 width: 160px;                 height: 80px;                 background: #a84909;                 border-radius: 40px;             }         </style>     </head>     <body>         <div class="oval"></div>     </body> </html> 

It gives me this:

enter image description here

To make a circle it works, but an oval not.

like image 441
rachid Avatar asked Nov 16 '14 19:11

rachid


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 make a half oval in CSS?

If you put 50% before the slash symbol, you will get a vertical half-ellipse. And if you put 50% after the slash symbol, you'll get a horizontal half-ellipse.


2 Answers

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

.oval {    width: 160px;    height: 80px;    background: #a84909;    border-radius: 50%;  }
<div class="oval"></div>
like image 132
Ali Aboussebaba Avatar answered Oct 02 '22 16:10

Ali Aboussebaba


You need to set the border radius in percentage :

Percentage : Denotes the size of the circle radius, or the semi-major and semi-minor axes of the ellipsis, using percentage values. Percentages for the horizontal axis refer to the width of the box, percentages for the vertical axis refer to the height of the box. Negative values are invalid.

source : MDN

For a detailed explanation of why pixel values for border-radius can't output an oval shape see Border-radius in percentage (%) and pixels (px)

Example :

border-radius: 50%; 

 .oval {     width: 160px;     height: 80px;     background: #a84909;     border-radius: 50%;   }
<div class="oval"></div>
like image 41
web-tiki Avatar answered Oct 02 '22 16:10

web-tiki