我正在用CSS制作进度条。我想把横梁内的部分弄斜。我该怎么做才能像图中所示?

.progress-bar{
height: 34px;
background: #0C0C0C;
display: flex;
flex: 1 auto;
width: 100%;
position: relative;
}
.progress-bar div{
width: 69%;
background: #1EA614;
height: 100%;
}
.progress-bar div span{
position: absolute;
font-size: 24px;
width: 100%;
left: 0;
justify-content: center;
align-items: center;
display: flex;
height: 100%;
}<div class="progress-bar">
<div>
<span>Level 5</span>
</div>
</div>
发布于 2020-07-05 01:05:44
您可以使用梯度来实现这一点,就像我下面所做的那样。
我唯一改变的是
background-image: linear-gradient(105deg, #1EA614 0%, #1EA614 85%, transparent 85%);本质上,我们声明一个渐变背景,在一个与你所给的照片大致一致的角度上。然后,我们设置这样的止损点:
请注意,这个数字,85%,确实需要一些调整,以确保截止始终是相同的。
这是您的演示,但是添加了这些代码。我还添加了一个动画,这样您就可以看到它在条形图的所有宽度阶段都能工作。
.progress-bar{
height: 34px;
background: #0C0C0C;
display: flex;
flex: 1 auto;
width: 250px;
position: relative;
}
.progress-bar div{
width: 100%;
background-size: cover;
background-position: -250px 0;
background-repeat: no-repeat;
background-image: linear-gradient(105deg, #1EA614 0%, #1EA614 96%, transparent 96%);
height: 100%;
animation: bar 2s linear infinite;
}
.progress-bar div span{
position: absolute;
font-size: 24px;
width: 100%;
left: 0;
justify-content: center;
align-items: center;
display: flex;
height: 100%;
}
@keyframes bar {
0% {
background-position: -250px 0;
}
100% {
background-position: 0 0;
}
}<div class="progress-bar">
<div>
<span>Level 5</span>
</div>
</div>
如果您有问题,它没有填充整个栏,您可以尝试只是移动渐变横条,而不是改变酒吧的宽度。我更新了我的例子来做这件事。
参考文献:
发布于 2020-07-05 01:33:42
.progress{
height: 34px;
background: #0C0C0C;
display: flex;
flex: 1 auto;
width: 100%;
position: relative;
}
.progress .progress-bar{
width: 60%;
background: #1EA614;
height: 100%;
position: relative;
overflow: hidden;
}
.progress span{
position: absolute;
font-size: 24px;
width: 100%;
left: 0;
justify-content: center;
align-items: center;
display: flex;
height: 100%;
}
.progress .progress-bar:after{
content: "";
position: absolute;
top: -1px;
right: -6.5px;
height: 115%;
width: 13px;
background: #0C0C0C;
transform: rotate(20deg);
} <div class="progress">
<div class="progress-bar"></div>
<span>Level 5</span>
</div>
https://stackoverflow.com/questions/62735859
复制相似问题