Is it possible to style a progressbar that reached its max-value differently in CSS than the one that hasn't started yet or is started?
for example doing something like
progress[max=value] {
background: green // color when maxed out
}
progress {
background: red;//default color
}
Or do I have to use Javascript to detect it?
WebKit/Blink provides two pseudo classes to style the progress element: -webkit-progress-bar is the pseudo class that can be used to style the progress element container. In this demo we'll change the background color, border-radius and then apply inset box shadow to the progress element container.
You should be able to do the following: progressbar. setMax(maxValue);
Use the <progress> tag to create a progress bar in HTML. The HTML <progress> tag specifies a completion progress of a task. It is displayed as a progress bar.
<progress>: The Progress Indicator element. The <progress> HTML element displays an indicator showing the completion progress of a task, typically displayed as a progress bar.
This answer assumes that we know the maximum value of the progress bar. I'm going to use the following markup:
<progress max=100 value=100></progress>
Our progress bar here has a maximum value of 100 and a value of 100, meaning it is at its completed state. From this we can use the [att=val] selector to target it at its completed state:
progress[value="100"] { ... }
Chris Coyier has an article on CSS Tricks which explains how the progress
element can be styled in Chrome, Firefox and IE10. Following this we can apply the styling to the completed progress bar. First we reset the style:
progress[value="100"] {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
Then we can specifically apply styling to ::-webkit-progress-value
and ::-moz-progress-bar
to target the foreground progress bar on both Chrome and Firefox. For this I'm setting a background colour of #f00
(red):
/* Chrome */
progress[value="100"]::-webkit-progress-value {
background:#f00;
}
/* Firefox */
progress[value="100"]::-moz-progress-bar {
background:#f00;
}
Finally we can add in the IE10 styling by simply adding a color
property on the main selector:
progress[value="100"] {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
/* IE10 */
color:#f00;
}
Here is a JSFiddle demo demonstrating this with two progress bars - the first at 50% and the second at 100%. For the lazy, here is the result across Chrome, Firefox and IE10:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With