Reputation: 29497
I'm trying to make a percentage bar for iOS, so I couldn't use the <input type="range" />
, then I'm doing it like this:
<div id="detailedPercentage">
<div id="percLabel">70%</div>
</div>
With this CSS, where perc.png
is a 1px
colored with rgb(136, 153, 170)
:
#detailedPercentage {
height: 32px;
width: 286px;
margin-right: 15px;
border: 1px solid #222;
background-image: url(../images/perc.png);
background-color: rgb(242, 242, 242);
background-repeat: repeat;
background-size: 70%;
}
#percLabel {
height: 32px;
width: 100%;
color: #222;
text-align: center;
font-family: Georgia;
line-height: 32px;
font-size: 19px;
background-color: transparent;
}
But the background is filling 100% of the box. What should I do to correct this?
Upvotes: 0
Views: 551
Reputation: 49208
You can use stacked elements to make a progress meter.
HTML - Note the percDisplay
element.
<div id="detailedPercentage">
<div id="percDisplay"></div>
<div id="percLabel">70%</div>
</div>
CSS - Note the position
properties.
#detailedPercentage {
height: 32px;
width: 480px;
margin: 15px;
border: 1px solid #222;
background-color: rgb(242, 242, 242);
position: relative;
}
#percDisplay {
position: absolute;
top: 0px;
left: 0px;
z-index: 1;
background-color: rgb(136, 153, 170);
width: 70%;
height: 32px;
}
#percLabel {
position: absolute;
top: 0px;
left: 0px;
z-index: 2;
height: 32px;
width: 100%;
color: black;
text-align: center;
font-family: Georgia;
line-height: 32px;
font-size: 19px;
background-color: transparent;
}
Upvotes: 1
Reputation: 8694
I had this exact same css problem (though not related to IOS) a couple of months ago and asked the question over here:
and I also asked this related question:
How widely supported are background-size and background-origin?
Perhaps those will help.
To see the solution working (on an incomplete, buggy page) take a look at the "Bid x Ask" column (ninth col from left) in this table.
Upvotes: 1