【发布时间】:2020-10-01 04:18:33
【问题描述】:
我想用纯 CSS 制作一个 0-100% 响应的仪表,颜色渐变从绿色到红色。我找到了一些示例,但无法在其中任何一个中正确使用渐变。经过一些测试,我设法让它有点工作。它基本上是一个带有线性渐变背景的背景 div 和一个带有半透明边框的白色前景 div,使用边框半径使它们变圆。当我旋转前景 div 时,它会显示或隐藏渐变背景 div 的部分。
但我有这个视觉故障,我不知道如何解决:
前景 div 的白色边框没有完全遮挡渐变 div。
这是我的测试代码(它可能包含我之前所做的所有测试中不必要的 css 规则):
https://jsfiddle.net/fLtzrg3w/
HTML:
<div class="c">
<div class="go">
<div class="g"></div>
<div class="gbg"></div>
</div>
</div>
CSS:
.c{
position: relative;
float:left;
text-align: center;
width: 50%;
padding: 25% 5px 0 5px;
height: 1rem;
overflow:hidden;
}
.go{
position: relative;
width: 100%;
overflow: hidden;
padding-top:100%;
margin-top: -50%;
}
.g{
position: absolute;
top: 0; left: 0;
width: 100%; height: 100%;
border-radius: 50%;
box-sizing: border-box;
border: 40px solid transparent;
border-bottom-color: #fff;
border-right-color: #fff;
transform: rotate(20deg);
background: white;
background-clip: padding-box;
z-index: 2;
}
.gbg{
position: absolute;
top: 0; left: 0;
width: 100%; height: 100%;
border-radius: 50%;
box-sizing: border-box;
background: linear-gradient(to right, green 0%, yellow 50%, red 100%);
z-index: 1;
}
如何让白色div完全覆盖背景渐变div?
【问题讨论】:
-
这可能会有所帮助:codepen.io/xgh/pen/ExaXgbb
-
@Mech 我想我看到了那个,但是在将它从固定宽度/高度转换为 % 后遇到了同样的问题,稍后再试一次。
-
NP。祝你好运! :)
标签: html css border linear-gradients