1

#slider1 {
  -webkit-appearance: slider-vertical; /* This makes ... */
  background-color: black;
  width: 1px;
  height: 100px;
}

#slider2 {
  -webkit-appearance: none; /* the difference. */
  background-color: black;
  width: 100px;
  height: 1px;
}

#slider1::-webkit-slider-thumb,
#slider2::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 25px;
  height: 25px;
  background: #04aa6d;
  cursor: pointer;
}

#slider1::-webkit-slider-thumb:hover,
#slider2::-webkit-slider-thumb:hover {
  width: 20px;
  height: 20px;
}
<input type="range" id="slider1" />
<input type="range" id="slider2" />

As seen here, the CSS styling was almost same for both sliders, except for the -webkit-appearance property. But the horizontal slider (which is the default slider) accepts the styling while the vertical slider rejects it. I am on Chrome. How to make it work? Thanks!

Book Of Flames
  • 316
  • 3
  • 13
  • Does it answer your question? https://stackoverflow.com/questions/18389224/how-to-style-html5-range-input-to-have-different-color-before-and-after-slider – Tony Stark May 24 '21 at 05:17
  • Does this answer your question? [How to display a range input slider vertically](https://stackoverflow.com/questions/15935837/how-to-display-a-range-input-slider-vertically) – Abhishek Pandey May 24 '21 at 05:18
  • @AbhishekPandey I have seen the page before, nothing was mentioned about styling. – Book Of Flames May 24 '21 at 05:20
  • @TonyStark That question doesn't seem to be about vertical slider styling :/ – Book Of Flames May 24 '21 at 05:21

4 Answers4

2

It seems like there is no work around available to design vertical range, what you can do is to rotate the default one.

.wrap {
  display: flex;
}

.slid1 {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100px;
  width: 30px;
}

#slider1,
#slider2 {
  -webkit-appearance: none;
  /* the difference. */
  background-color: black;
  width: 100px;
  height: 1px;
}

#slider1 {
  -webkit-appearance: none;
  /* This makes ... */
  transform: rotate(270deg);
  transform-origin: center;
}

#slider1::-webkit-slider-thumb,
#slider2::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 25px;
  height: 25px;
  background: #04aa6d;
  cursor: pointer;
}

#slider1::-webkit-slider-thumb:hover,
#slider2::-webkit-slider-thumb:hover {
  width: 20px;
  height: 20px;
}
<div class="wrap">
  <div class="slid1">
    <input type="range" id="slider1" />
  </div>
  <div class="slid2">
    <input type="range" id="slider2" />
  </div>
</div>

Source

Edit: As per your comment, I have wrapped sliders into flex containers to align them.

Abhishek Pandey
  • 13,302
  • 8
  • 38
  • 68
  • Yes, I tried to work with that solution, but as you can see, the code produces a slider shifted to little right. Do you have a solution to fix that? I mean a general solution, not particularly this one. – Book Of Flames May 24 '21 at 05:32
0

In order to add custom styling to range slider, you need to set a css property -webkit-appearance: none; which you did in #slider2 but you missed it in #slider1. Try the following code

<input type="range" id="slider1" />
<input type="range" id="slider2" />
<style type="text/css">
    #slider1 {
    -webkit-appearance: none; /* This makes ... */
    background-color: black;
    width: 1px;
    height: 100px;
    }
    
    #slider2 {
    -webkit-appearance: none; /* the difference. */
    background-color: black;
    width: 100px;
    height: 1px;
    }
    
    #slider1::-webkit-slider-thumb,
    #slider2::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 25px;
    height: 25px;
    background: #04aa6d;
    cursor: pointer;
    }
    
    #slider1::-webkit-slider-thumb:hover,
    #slider2::-webkit-slider-thumb:hover {
    width: 20px;
    height: 20px;
    }
</style>

Then you will find the vertical slider

Liberty
  • 1
  • 3
0

/* can you please try this below CSS code along with your css */

/*Chrome*/
@media screen and (-webkit-min-device-pixel-ratio:0) {
    input[type='range'] {
      overflow: hidden;
      width: 80px;
      -webkit-appearance: none;      
    }    
    input[type='range']::-webkit-slider-runnable-track {
      height: 10px;
      -webkit-appearance: none;
      color: #13bba4;
      margin-top: -1px;
    }
       
}
wpdevloper_j
  • 330
  • 2
  • 12
0

#slider1 {
  margin-top: 50px;
  transform: rotate(90deg);
}

#slider1, #slider2 {
  -webkit-appearance: none; /* the difference. */
  background-color: black;
  width: 100px;
  height: 1px;
}

#slider1::-webkit-slider-thumb,
#slider2::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 25px;
  height: 25px;
  background: #04aa6d;
  cursor: pointer;
}

#slider1::-webkit-slider-thumb:hover,
#slider2::-webkit-slider-thumb:hover {
  width: 20px;
  height: 20px;
}
<input type="range" id="slider1" />
<input type="range" id="slider2" />
pullidea-dev
  • 1,768
  • 1
  • 7
  • 23