简体   繁体   English

HTML/CSS 中的进度条

[英]Progress bar in HTML/CSS

 dd { 
    /*position: relative; /* IE is dumb */
    display: block;                 
    float: left;     
    width: 500px; 
    height: 16px; 
    margin: 0 0 2px; 
    background: url("white3.gif"); 
 }

 dd div.blue { 
    /*position: relative; */
    background: url("blue.gif"); 
    height: 16px; 
    width: 75%; 
    text-align:right; 
    display:block;
 }

HTML: HTML:

<dd>
    <div class="blue" style="width:35%;"> 
</dd>

This creates a white bar and fills it with blue 35%.这将创建一个白色条并用蓝色 35% 填充它。

Now I would like to fill the SAME progress bar with two different values.现在我想用两个不同的值填充相同的进度条。 For example, if value A was 30% and value B was 40%, 70% of the bar would be filled, but the percentage of each could be seen by a difference in colors.例如,如果值 A 为 30%,值 B 为 40%,则将填充 70% 的条形图,但可以通过 colors 中的差异看出每个条形的百分比。 Value A and B can come in any order on the bar, as long as I can tell there are two different things and "see" how much each one is taking up.值 A 和 B 可以在条形图上以任何顺序出现,只要我能分辨出有两种不同的事物并“查看”每个事物占用了多少。

Any suggestions?有什么建议么?

Thanks.谢谢。

Are you looking for something like this?你在寻找这样的东西吗?

CSS: CSS:

div.dd { 
   /*position: relative; /* IE is dumb */
    display: block;                 
    float: left;     
    width: 500px; 
    height: 16px; 
    margin: 0 0 2px; 
    background: #fff; 
}

div.dd div.blue { 
    /*position: relative; */
    background: #00f; 
    height: 16px; 
    width: 75%; 
    text-align:right; 
    display:block;
    float: left;
}
div.dd div.red { 
    /*position: relative; */
    background: #f00; 
    height: 16px; 
    width: 75%; 
    text-align:right; 
    display:block;
    float: left;
}

HTML: HTML:

<div class="dd">
    <div class="blue" style="width:35%;"></div>
    <div class="red" style="width:10%;"></div>
</div>

I'm not sure why you're using the dd tag (for me, this tag causes the divs to render beneath the dd tag, rather than inside).我不确定你为什么使用 dd 标签(对我来说,这个标签会导致 div 呈现在 dd 标签下面,而不是在里面)。

<div class="progressbar">
   <div class="inner1" style="width: 30%; background-color: blue;"><b>Value A</b></div>
   <div class="inner2" style="width: 40%; background-color: red;"><b>Value B</b></div>
</div>

Then the CSS:然后是 CSS:

.progressbar {
   background-color: #1e1e1e;
   color: white;
   height: 25px;
   width: 115px;
}
.inner1, .inner2 {
   height: 100%;
   /* Change width with javascript */
}

If you just want one value in a progress bar, there is a tutorial here .如果您只想要进度条中的一个值,这里有一个教程。

I suggest layering another bar over it and shifting it left/right as needed.我建议在其上放置另一个条并根据需要向左/向右移动。

If the bars aren't supposed to stretch the length of the viewport, you could put them in a div with overflow:hidden to keep the illusion intact.如果条形图不应该拉伸视口的长度,则可以将它们放在具有溢出的 div 中:隐藏以保持错觉完好无损。

Edit:编辑:

I just figured out why I wanted to do it that way and not follow what you'd started.我只是想明白为什么我想那样做而不是按照你的开始。 When I did something similar before, it was using images, where changing the width of course have mangled the overlaying image.当我之前做类似的事情时,它使用的是图像,改变宽度当然会破坏覆盖的图像。

With just plain colors, I'm sure you could get away with just using the size.仅使用普通的 colors,我相信您只需使用尺寸即可。 But I'd still use CSS to layer one over the other.但我仍然会使用 CSS 一层层叠加。

<div style="height: 5px; background-color: green; width: 100%;">
    <div id="progress_bar" style="height: 5px; background-color: red; width: 10%;"></div>
</div>  

And after that:在那之后:

$('#progress_bar').css('width', '30%');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM