Styling the text on each side of a <input type="range"> tag

I would like to add some CSS styling to the words that are on either side of the tags.

Here is my code:

<fieldset>
    <legend>Your Indicators</legend><br>
        <label for="height" class="margin">Height:</label>
        Short<input type="range" id="height" name="height" min="0" max="100">Tall<br>
        <label for="salary" class="margin">Salary:</label>
        Poor<input type="range" id="salary" name="salary" min="0" max="100">Rich
</fieldset>

Answers


You can wrap the text on either side in spans with classes, then style them by class via CSS as follows.

Live Demo:

fieldset > * {
    vertical-align: middle;
}

.leftlabel, .rightlabel {
    display: inline-block;
    width: 50px;
    padding: 2px;
    text-align: center;
}

.leftlabel {
    background-color: red;
    color: white;
}
.rightlabel {
    background-color: purple;
    color: white;
}

label {
    display: inline-block;
    width: 50px;
}
<fieldset>
    <legend>Your Indicators</legend><br>
      <label for="height" class="margin">Height:</label>
      <span class="leftlabel">Short</span>
      <input type="range" id="height" name="height" min="0" max="200" style="width: 200px">
      <span class="rightlabel">Tall</span>
      <br>
      <label for="salary" class="margin">Salary:</label>
      <span class="leftlabel">Poor</span>
      <input type="range" id="salary" name="salary" min="0" max="200" style="width: 200px">
      <span class="rightlabel">Rich</span>
  </fieldset>

The easiest way is to make the left and right labels a class which can be referenced from the style block: Now the style statements are

.left{
  text-align: center;
  width:40px;
  color:white;
  background: darkred;
  padding:3px;
}
.right{
  text-align: center;
  width:40px;
  color:white;
  background: purple;
    padding:3px;
}


     -------------HTML-------------------
<fieldset>
    <legend>Your Indicators</legend>
    <label>Height:</label>
        <label for="height" class="left">Short</label>
  <input type="range" id="height" name="height" min="0" max="100" step="1" value="81">
  <label for="height" class="right">Tall</label><br>
    <label for="salary">Salary:</label>
        <label for="salary" class="left">Low</label>
         <input type="range" id="salary" name="salary" min="0" max="100" step="1" value="18">
        <label for="salary" class="right">High</label> <br>
</fieldset> <br>

What about using input instead of label? :) you can easily style input, and yes, it can be textarea


Try this in your css, sorry I'm on a phone so can't test first.

label {

text-align:center;

} 

Need Your Help

Check if password and username input match in Python?

python tkinter username tkinter-entry

I have made a little program that should ask you for your password and username. After you have entered your details it should check if the password and the username are correct. how do i approach ...

Trying to update mysql database form in php

php mysql

My database manages to retrieve values when I navigate from the previous page.