Question

I know how to create a css circle with border radius etc, but i'm interested in creating a css only doughnut shape roughly like this one here -> enter image description here

It would be one div but curved round back onto itself,

any ideas??

Was it helpful?

Solution

<div class="doughnut"></div>


.doughnut { 
    border: 50px solid #f00;
    border-radius: 100px;
    height:100px;
    width:100px;
}

OTHER TIPS

Demo

div{width:200px; height:200px; border:1px solid black; position:relative; border-radius:200px;}
div:before{content:''; width:50px; height:50px; display:block; position:absolute; top:75px; left:75px; border:1px solid black; border-radius:200px;}

This shape can also be drawn with css3 radial-gradient():

div {
  background: radial-gradient(circle, transparent 40%, purple 40%);
}

body {
  background: linear-gradient(orange, red) no-repeat;
  min-height: 100vh;
  margin: 0;
}

div {
  background: radial-gradient(circle, transparent 40%, purple 40%);
  border-radius: 100%;
  height: 300px;
  width: 300px;
  margin: 25px;
}
<div></div>

Just set the border radius to 50% of the div width:

Working sample

Th colors are off but this is as simple as it gets with some backwards compatibility. Can answer any questions later on if need be.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>CSS Donut</title>
<style>
#div1
{
 background-color: #f00;
 border: #f0f solid 1px;
 height: 100px;
 width: 100px;
 border-radius: 50px;
 -webkit-border-radius: 50px;
 -moz-border-radius: 50px;
}
#div2
{
 background-color: #0f0;
 border: #f0f solid 1px;
 height: 60px;
 margin: 20px 0px 0px 20px;
 width: 60px;
 border-radius: 30px;
 -webkit-border-radius: 30px;
 -moz-border-radius: 30px;
}
</style>
</head>

<body>
<div id="div1"><div id="div2">&#160;</div></div>

</body>
</html>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top