gpt4 book ai didi

css - 如何使用 CSS 创建一个倾斜的进度条?

转载 作者:行者123 更新时间:2023-12-04 09:33:07 24 4
gpt4 key购买 nike

我正在用 CSS 制作进度条。我想让酒吧内的部分的末端倾斜。我该怎么做如图?
enter image description here

.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>

最佳答案

这是一个代码较少的简化版本,您可以轻松控制曲线、颜色和进度百分比

.progress-bar {
--s:20px; /* define the curve (make bigger to increase the curve, smaller to reduce)*/
--p:50; /* percentage of the progress without unit */
--c:#1EA614; /* color */

height: 34px;
line-height:34px;
background:
linear-gradient(to bottom right,var(--c) 49%,transparent 50%)
calc(1%*var(--p) + var(--p,0)/100*var(--s)) 0 / var(--s) 100%,
linear-gradient(var(--c) 0 0)
0 / calc(1%*var(--p)) 100%,
#0C0C0C;
background-repeat:no-repeat;
text-align: center;
font-size: 24px;
color:#fff;
margin:5px;
}
<div class="progress-bar">
Level 5
</div>

<div class="progress-bar" style="--p:30;--c:red;--s:10px">
Level 5
</div>

<div class="progress-bar" style="--p:70;--c:lightblue;--s:40px">
Level 5
</div>

<div class="progress-bar" style="--p:100;--s:40px">
Level 5
</div>

关于css - 如何使用 CSS 创建一个倾斜的进度条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62735859/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com