Skip to content

Instantly share code, notes, and snippets.

@LeaVerou
Last active October 20, 2018 18:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save LeaVerou/9ef99ce3555ba569c24c7532ef37dc9a to your computer and use it in GitHub Desktop.
Save LeaVerou/9ef99ce3555ba569c24c7532ef37dc9a to your computer and use it in GitHub Desktop.
Progress bar that changes width AND color using a CSS variable
/**
* Progress bar that changes width AND color using a CSS variable
*/
div {
display: flex;
height: .8em;
margin: 1em 0;
background: hsl(220,10%,80%);
}
div::before {
content: "";
width: calc(var(--value) * 100%);
background: hsl(calc(var(--value) * 90), 50%, 50%);
}
<div class="progress" style="--value: .02"></div>
<div class="progress" style="--value: .1"></div>
<div class="progress" style="--value: .3"></div>
<div class="progress" style="--value: .5"></div>
<div class="progress" style="--value: .7"></div>
<div class="progress" style="--value: .9"></div>
<div class="progress" style="--value: 1"></div>
// alert('Hello world!');
{"view":"split","fontsize":"100","seethrough":"","prefixfree":"","page":"css"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment