CSS - Pie Chart Icon
Code example for drawing a simple pie chart icon using HTML and CSS.
The HTML code sets the class name "pie-chart-icon" for the <div> tag which will make up the pie chart icon element.
It sets <div> tags for the frame and 3 pie slices.
<div class="pie-chart-icon">
<div></div><div></div><div></div><div></div>
</div>
The CSS custom property "--w" sets the base size.
The example stacks 1/4 circle slices using z-index.
/* Pie Chart Icon */
.pie-chart-icon {
--w: 300px; /* Base Size */
position: relative;
width: var(--w);
height: var(--w);
}
/* Body */
.pie-chart-icon div:nth-child(1) {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 95%;
height: 95%;
border-radius: 50%;
background-color: #4169e1;
}
/* A */
.pie-chart-icon div:nth-child(2) {
position: absolute;
top: 5%;
left: 5%;
transform: translate(-50%, -50%);
border: solid #dc143c;
border-width: calc(var(--w) * 0.45) calc(var(--w) * 0.45) 0 0;
border-radius: calc(var(--w) * 0.45) 0 0 0;
transform-origin: right bottom;
transform: rotate(90deg);
z-index: 3;
}
/* B */
.pie-chart-icon div:nth-child(3) {
position: absolute;
top: 5%;
left: 5%;
transform: translate(-50%, -50%);
border: solid #ff7f50;
border-width: calc(var(--w) * 0.45) calc(var(--w) * 0.45) 0 0;
border-radius: calc(var(--w) * 0.45) 0 0 0;
transform-origin: right bottom;
transform: rotate(170deg);
z-index: 2;
}
/* C */
.pie-chart-icon div:nth-child(4) {
position: absolute;
top: 5%;
left: 5%;
transform: translate(-50%, -50%);
border: solid #ffa07a;
border-width: calc(var(--w) * 0.45) calc(var(--w) * 0.45) 0 0;
border-radius: calc(var(--w) * 0.45) 0 0 0;
transform-origin: right bottom;
transform: rotate(230deg);
}