반응형
$pieBg: #ddd;
$piePoint: #fc595d;
.pie-chart {
position: relative;
width: 80px;
height: 80px;
border-radius: 50%;
background: $pieBg;
}
.pie {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
&.less {
clip: rect(0px, 80px, 80px, 40px);
}
&.more {
clip: rect(0, 80px, 80px, 0);
}
}
.pie-piece {
position: absolute;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
border-radius: 50%;
background-color: $piePoint;
clip: rect(0px, 80px, 80px, 40px);
@at-root .less &.right {
display: none;
}
@at-root .more &.right {
display: block;
}
}
.percentage {
background: #fff;
width: 70%;
height: 70%;
border-radius: 50%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
align-items: center;
justify-content: center;
color: $piePoint;
font-size: 20px;
}
.unit {
font-size: 16px;
}
<div class="pie-chart">
<div class="pie less"> <!-- if percentage <= 50% -->
<!-- rotate: -180 + ( 3.6 * percentage ) -->
<div class="pie-piece" style="transform:rotate( -108deg )"></div>
<div class="pie-piece right"></div>
</div>
<div class="percentage">
20<span class="unit">%</span>
</div>
</div>
<hr />
<div class="pie-chart">
<div class="pie more"> <!-- 51% <= percentage < 100& -->
<!-- rotate: 3.6 * (percentage - 50 ) -->
<div class="pie-piece" style="transform:rotate( 144.0deg )"></div>
<div class="pie-piece right"></div>
</div>
<div class="percentage">
90<span class="unit">%</span>
</div>
</div>
반응형
'css > e.g.' 카테고리의 다른 글
[PC] Gradient Doughnut 2 / Loading (0) | 2021.09.25 |
---|---|
[PC] Gradient Doughnut 1 (0) | 2021.09.24 |
[css-real] 웹접근성을 고려한 .blind(hidden) 처리 (0) | 2021.01.20 |
[css-real] 드래그(drag) 막기 (4) | 2021.01.11 |
[css-real] 형광펜으로 표시한 듯 효과주기 (0) | 2021.01.10 |
댓글