Reputation: 326
#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!
Upvotes: 1
Views: 1263
Reputation: 13568
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>
Edit: As per your comment, I have wrapped sliders into flex containers to align them.
Upvotes: 2
Reputation: 1803
#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" />
Upvotes: 0
Reputation: 340
/* 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;
}
}
Upvotes: 0
Reputation: 1
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
Upvotes: 0