【发布时间】:2016-06-29 20:40:46
【问题描述】:
我的 css 和 html 代码是:https://jsfiddle.net/z2cc11yk/
html:
<div class="progressbar-container">
<div class="progressbar-text">125%</div>
<div class="progressbar-progress" style="background-color: red; width: 100%; transition: width 200ms ease 0s; height: 20px;"></div>
</div>
<div class="progressbar-container">
<div class="progressbar-text">50%</div>
<div class="progressbar-progress" style="background-color: rgb(11, 211, 24); width: 50%; transition: width 200ms ease 0s; height: 20px;"></div>
</div>
css:
.progressbar-progress{
background-color: rgb(11, 211, 24);
width: inherit;
transition: width 200ms ease 0s;
height: 100%;
position:absolute;
margin:0 10;
z-index: -2;
}
.progressbar-text{
width: 100%;
height: 100%;
position:absolute;
z-index: -1;
}
.progressbar-container{
border-style: solid;
height: 20px;
border-width:1px;
text-align:center;
width: 100%;
}
问题是我使用内部元素的绝对位置,因为我需要在进度条顶部显示文本。
但我发现如果 100% 填充,子元素大于父元素。
我的意思是类进度条进度大于进度条容器。 如何在进度条包含框内进行限制?
另一个问题是为什么填充了高度,而子元素的宽度大于父元素?
【问题讨论】: