Reputation: 4773
I have this code:
<div style="border:1px solid #afafaf;background-color:#efefef;width:100px;height:14px;">
<div style="text-align:center;width:50px;height:14px;background-color:green;">
50%
</div>
</div>
How can i put the 50% in the middle if the 1st DIV , the 2nd div might have width of 0 to 100 px (progress bar)
Upvotes: 0
Views: 1060
Reputation: 228162
position: relative
to your outer div.Whatever width
your progress bar has, it won't affect the text div.
HTML:
<div style="border:1px solid #afafaf;background-color:#efefef;width:100px;height:14px;position:relative">
<div style="text-align:center;width:50px;height:14px;background-color:green;"></div>
<div id="text">50%</div>
</div>
CSS:
#text {
position: absolute;
width: 100%;
top: 0;
left: 0;
text-align: center
}
Upvotes: 5
Reputation: 17898
For example have a third div with margin-left:auto;margin-right:auto
which centers this div into the middle
Upvotes: 0