我正在尝试使用纯CSS来制作具有背景渐变的径向进度条。根据我们提供的.progress-47
或.progress-90
类,Sass for循环会改变径向的行为。我需要以逆时针方向创建相同的效果。完整代码可在CodePen中找到。
<div class="item progress-47">
<div class="radial-inner-bg"><span>47%</span></div>
</div>
<div class="item progress-33">
<div class="radial-inner-bg"><span>3/3</span></div>
</div>
<div class="item progress-95">
<div class="radial-inner-bg"><span>95%</span></div>
</div>
<div class="item progress-85">
<div class="radial-inner-bg"><span>85%</span></div>
</div>
$step: 1; // step of % for created classes
$loops: 100;
$increment: (360 / $loops);
$half: round($loops / 2);
@for $i from 0 through $loops {
.progress-#{$i*$step} {
@if $i < 50 {
$nextdeg: 90deg + ( $increment * $i );
background-image: linear-gradient(90deg, $light-gray 50%, transparent 50%, transparent), linear-gradient($nextdeg, $medium-yellow 50%, $light-gray 50%, $light-gray);
}
@else {
$nextdeg: -90deg + ( $increment * ( $i - $half ) );
background-image: linear-gradient($nextdeg, $medium-yellow 50%, transparent 50%, transparent), linear-gradient(270deg, $medium-yellow 50%, $light-gray 50%, $light-gray);
}
}
}
答案 0 :(得分:1)
我强烈反对使用CSS 来阻止生成此径向进度条。 SVG是这类东西的最佳工具。使用CSS,即使有可能,也需要很多工作和很多课程。
<强>解决方案:强>
要将径向进度条更改为逆时针方向,我们只需更改渐变定义即可。需要修改渐变的角度,并且需要像下面的代码块中那样切换颜色:
@for $i from 0 through $loops {
.progress-#{$i*$step} {
@if $i < 50 {
$nextdeg: 90deg - ( $increment * $i ); /* angle modified */
background-image: linear-gradient(90deg, transparent 50%, $light-gray 50%), linear-gradient($nextdeg, $light-gray 50%, $medium-yellow 50%); /* colors switched */
}
@else {
$nextdeg: -90deg - ( $increment * ( $i - $half ) ); /* angle modified */
background-image: linear-gradient($nextdeg, transparent 50%, $medium-yellow 50%), linear-gradient(270deg, $light-gray 50%, $medium-yellow 50%); /* colors switched */
}
}
}
<强>解释强>
my answer here中提供了有关渐变如何产生径向进度条的完整说明。
演示:此处提供演示 - CodePen Demo。