Segments in a circle using CSS3
Solution 1:
Yes, you can get such slices of custom angles using either one of the following two methods:
- If you don't need the slices to be elements themselves, the you can simply do it with one element and linear gradients - see this rainbow wheel I did last month.
- If you need the slices to be elements themselves, then you can do it by chaining rotate and skew transforms - see this circular menu I did a while ago.
For #2, see also this very much simplified example I did right now.
.pie {
overflow:hidden;
position: relative;
margin: 1em auto;
border: dashed 1px;
padding: 0;
width: 32em; height: 32em;
border-radius: 50%;
list-style: none;
}
.slice {
overflow: hidden;
position: absolute;
top: 0; right: 0;
width: 50%; height: 50%;
transform-origin: 0% 100%;
}
.slice:first-child {
transform: rotate(15deg) skewY(-22.5deg);
}
.slice-contents {
position: absolute;
left: -100%;
width: 200%; height: 200%;
border-radius: 50%;
background: lightblue;
}
.slice:first-child .slice-contents {
transform: skewY(22.5deg); /* unskew slice contents */
}
.slice:hover .slice-contents { background: violet; } /* highlight on hover */
<ul class='pie'>
<li class='slice'>
<div class='slice-contents'></div>
</li>
<!-- you can add more slices here -->
</ul>
Solution 2:
Yes you can: http://jsfiddle.net/elias94xx/3rx7w/, http://jsfiddle.net/elias94xx/3rx7w/2/
#chart {
width: 0;
height: 0;
border-right: 60px solid purple;
border-top: 60px solid transparent;
border-left: 60px solid transparent;
border-bottom: 60px solid transparent;
border-radius: 60px;
-moz-border-radius: 60px;
-webkit-border-radius: 60px;
}
<div id="chart"></div>
.chart {
position: absolute;
width: 0;
height: 0;
border-radius: 60px;
-moz-border-radius: 60px;
-webkit-border-radius: 60px;
}
#chart1 {
border-right: 60px solid red;
border-top: 60px solid transparent;
border-left: 60px solid transparent;
border-bottom: 60px solid transparent;
}
#chart2 {
border-right: 60px solid transparent;
border-top: 60px solid green;
border-left: 60px solid transparent;
border-bottom: 60px solid transparent;
}
#chart3 {
border-right: 60px solid transparent;
border-top: 60px solid transparent;
border-left: 60px solid blue;
border-bottom: 60px solid transparent;
}
#chart4 {
border-right: 60px solid transparent;
border-top: 60px solid transparent;
border-left: 60px solid transparent;
border-bottom: 60px solid yellow;
}
<div id="chart1" class="chart"></div>
<div id="chart2" class="chart"></div>
<div id="chart3" class="chart"></div>
<div id="chart4" class="chart"></div>
Source: http://www.paulund.co.uk/how-to-create-different-shapes-in-css