Building the CSS Variable Booth š¤£
We'll cover the following...
In case you missed it, below is what weāll build.
Type any color values within the red boxes, and move the range slider on the top right too!
This is a superb example of updating CSS variables with Javascript and the reactivity that comes with it.
Letās see how to build this.
The Markup
Here are the necessary components.
- A range input
- A container to hold the instructions
- A section to hold a list of other boxes each containing input fields
The markup turns out to be simple.
Here It is:
<main class="booth">
<aside class="slider">
<label>Move this š </label>
<input class="booth-slider" type="range" min="-50" max="50" value="-50" step="5"/>
</aside>
<section class="color-boxes">
<div class="color-box" id="1"><input value="red"/></div>
<div class="color-box" id="2"><input/></div>
<div class="color-box" id="3"><input/></div>
<div class="color-box" id="4"><input/></div>
<div class="color-box" id="5"><input/></div>
<div class="color-box" id="6"><input/></div>
</section>
<footer class="instructions">
šš» Move the slider<br/>
šš» Write any color in the red boxes
</footer>
</main>
Here a few things to point your attention to.
- The range input represents values from
-50
to50
with a step value of5
Also, the value of the range input is the minimum value,-50
If you arenāt sure how the range input works, check it out on w3schools - Note how the section with class
.color-boxes
contains other.color-box
containers. Within these containers are input fields. It is perhaps worth mentioning that the first input has a default value of red.
Having understood the structure of the document, go ahead and style it like so:
- Take the
.slider
and.