进度条不同颜色

你如何在CSS中制作进度条,该进度条将具有基于0%到20%红色,20%到40%蓝色等值的颜色...另外,我想一直显示颜色,而不仅仅是当它达到值时(这样,进度条的一部分将是红色,部分蓝色和其他颜色从一开始就消失了,并且颜色会随着值的下降而消失)。


有只小跳蛙
浏览 223回答 2
2回答

烙印99

如果您尝试按照当前进度实现渐变进度条,请尝试在CSS中使用属性。linear-gradient()这是一个工作模型:#prog-bar-cont {&nbsp; width: 75vw;&nbsp; height: 2.5em;}#prog-bar-cont #prog-bar {&nbsp; background: #ffff;&nbsp; width: 100%;&nbsp; height: 100%;&nbsp; border-color: #000;&nbsp; border-style: solid;&nbsp; border-radius: 50px;&nbsp; overflow: hidden;&nbsp; position: relative;}#prog-bar-cont #prog-bar #background {&nbsp; width: 100%;&nbsp; height: 100%;&nbsp; position: absolute;&nbsp; top: 0;&nbsp; left: 0;&nbsp;&nbsp;&nbsp; /*Actual Stuff*/&nbsp; background: linear-gradient(-90deg, violet, #30b3fc, #70dc23, yellow, orange, #ff1076);&nbsp; -webkit-clip-path: inset(0 100% 0 0);&nbsp; clip-path: inset(0 100% 0 0);&nbsp; transition: all 3s;&nbsp; -webkit-transition: all 3s;}#prog-bar-cont:hover #prog-bar #background {&nbsp; -webkit-clip-path: inset(0 0 0 0);&nbsp; clip-path: inset(0 0 0 0);}<h1>Rainbow Progress Bar</h1><p>Try hovering over the bar</p><div id='prog-bar-cont'>&nbsp; <div id="prog-bar">&nbsp; &nbsp; <div id="background"></div>&nbsp; </div></div>

回首忆惘然

您可以通过将进度条嵌套在父元素中并应用css属性来实现此目的。overflow: hidden您可以将类的 更改为所需的百分比。即 将显示 60% 的条形图。widthbar-clippercalc(300px * 0.6).bar-clipper {&nbsp; &nbsp; width: calc(300px * 0.8);&nbsp; &nbsp; height: 20px;&nbsp; &nbsp; overflow: hidden;&nbsp; &nbsp; position: absolute;}.bar-wrapper {&nbsp; &nbsp; width: 300px;&nbsp; &nbsp; height: 20px;&nbsp; &nbsp; display: flex;&nbsp; &nbsp; position: absolute;}.bar-wrapper span {&nbsp; &nbsp; width: 100%;&nbsp; &nbsp; height: 100%;}.bar-wrapper .bar1 {&nbsp; &nbsp; background-color: #163f5f;}.bar-wrapper .bar2 {&nbsp; &nbsp; background-color: #21639b;}.bar-wrapper .bar3 {&nbsp; &nbsp; background-color: #3caea3;}.bar-wrapper .bar4 {&nbsp; &nbsp; background-color: #f6d65b;}.bar-wrapper .bar5 {&nbsp; &nbsp; background-color: #ed543b;}<body>&nbsp; &nbsp; <div class="bar-clipper">&nbsp; &nbsp; &nbsp; &nbsp; <div class="bar-wrapper">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="bar1"></span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="bar2"></span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="bar3"></span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="bar4"></span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="bar5"></span>&nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; </div></body>小提琴链接:&nbsp;https://jsfiddle.net/L13yrgbm/
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript