【问题标题】:Multicolor progress bar using CSS使用 CSS 的多色进度条
【发布时间】:2018-09-24 11:42:55
【问题描述】:

我想创建一个多色进度条,请帮我写代码。进度小于50会显示红色当进度>50

【问题讨论】:

标签: javascript html css bootstrap-4


【解决方案1】:

您需要为进度条创建一个 div,然后您只需在进度条 div 中添加 div。 `

<div class="bar">
    <div class="fifty">
        <p>50%</p>
    </div>
    <div class="twentyfive">
        <p>25%</p>
    </div>
    <div class="ten">
        <p>10%</p>
    </div>
</div>

`

CSS 可能是这样的: `

    .bar {
        width: 100%;
        height: 30px;
        border-radius: 10px;
        background-color: #b3b3b3;
        color: white;
        text-align: center;
    }

    .fifty {
        width: 50%;
        height: 100%;
        background-color: green;
        float: left;
        border-top-left-radius: 10px;
        border-bottom-left-radius: 10px;
    }

    .twentyfive {
        width: 25%;
        height: 100%;
        background-color: orange;
        float: left;
    }

    .ten {
        width: 10%;
        height: 100%;
        background-color: red;
        float: left;
    }

`

【讨论】:

  • 非常感谢。我知道该怎么做,
【解决方案2】:

我创建了一个多色进度条。 在我的 codepen 上查看:https://codepen.io/onlintool24/pen/dyVJrww

只需要改变var的progressval值,就可以看到多色进度条了。

var progressval = 50;
var elm = document.getElementsByClassName('progressab')[0];
elm.style.width = progressval+"%";

elm.innerText = "You're "+progressval+"% There!";

if(progressval>90 && progressval<=100 ){   elm.style.backgroundColor = 'blue';                                 
}else if(progressval>50 && progressval<90 ){ elm.style.backgroundColor = 'green';
}else if(progressval<=50){ elm.style.backgroundColor = 'red';
}
.progressa {
    border-radius: 50px !important;
    height: 35px;
    line-height: 36px;
    font-size: 14px;
    overflow: hidden;
    height: 35px;
    margin-bottom: 20px;
    background-color: rgba(0,0,0,0.5);
    border-radius: 4px;
    -webkit-box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
    line-height: 36px;
    height: 35px;
    font-size: 14px;
    border: 3px solid transparent;
}
.progressab {
    background-image: -webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);
    background-image: -o-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);
    -webkit-background-size: 40px 40px;
    background-size: 40px 40px;
    -webkit-transition: width .25s ease,height .25s ease,font-size .25s ease;
    -moz-transition: width .25s ease,height .25s ease,font-size .25s ease;
    -ms-transition: width .25s ease,height .25s ease,font-size .25s ease;
    -o-transition: width .25s ease,height .25s ease,font-size .25s ease;
    transition: width .25s ease,height .25s ease,font-size .25s ease;
    width: 0;
    color: #fff;
    text-align: center;
    font-family: 'Open Sans',sans-serif !important;
    animation: progress-bar-stripes 2s linear infinite reverse;
}

@keyframes progress-bar-stripes{
0% {
    background-position: 40px 0;
}
100% {
    background-position: 0 0;
}
}
<div class="progressa">
<div class="progressab" style="    background-color: rgb(178, 222, 75);"></div>
</div>

【讨论】:

    猜你喜欢
    • 2015-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-12
    • 2021-08-30
    • 1970-01-01
    • 2013-04-03
    • 1970-01-01
    相关资源
    最近更新 更多