I have a input type range inside a div and I'm using the pseudo element 'before' as a circle. My intention is for it to be like the thumb at the starting position: I have the following html:
<div class="range">
<input type="range" name="" class="progress" value="0" max="100" min="0"/>
</div>
with the following css:
.range::before{
content: '';
display: inline-block;
width: 15px;
height: 15px;
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
border-radius: 15px;
background-color: #69b6d5;
}
Here is a functioning fiddle
My intention is to make the before element at the same position as the beginning of the range.
Added inline-block to .range::before and input and aligned them vetically using vertical-align: middle.
Set width of input to width: calc(100% - 15px). This 15px is the width of the .range::before element.
Bring the .range::before over the yellow dot using transform: translate(100%, 0)
See demo below:
/* RANGE */
input[type=range] {
-webkit-appearance: none;
margin: 10px 0;
width: calc(100% - 15px);
display: inline-block;
vertical-align: middle;
padding: 0;
border: none;
}
input[type=range]:focus {
outline: none;
}
input[type=range]::-webkit-slider-runnable-track {
width: 100%;
height: 3px;
cursor: pointer;
animate: 0.2s;
box-shadow: 0px 0px 0px #000000;
background: #FFE000;
border-radius: 7px;
border: 0px solid #FFE000;
}
input[type=range]::-webkit-slider-thumb {
box-shadow: 0px 0px 0px #FFE000;
border: 2px solid #FFE000;
height: 15px;
width: 15px;
border-radius: 15px;
background: #FFE000;
cursor: pointer;
-webkit-appearance: none;
margin-top: -7px;
}
input[type=range]:focus::-webkit-slider-runnable-track {
background: #FFE000;
}
input[type=range]::-moz-range-track {
width: 100%;
height: 3px;
cursor: pointer;
animate: 0.2s;
box-shadow: 0px 0px 0px #000000;
background: #FFE000;
border-radius: 7px;
border: 0px solid #FFE000;
}
input[type=range]::-moz-range-thumb {
box-shadow: 0px 0px 0px #FFE000;
border: 2px solid #FFE000;
height: 15px;
width: 15px;
border-radius: 15px;
background: #FFE000;
cursor: pointer;
}
input[type=range]::-ms-track {
width: 100%;
height: 3px;
cursor: pointer;
animate: 0.2s;
background: transparent;
border-color: transparent;
color: transparent;
}
input[type=range]::-ms-fill-lower {
background: #FFE000;
border: 0px solid #FFE000;
border-radius: 14px;
box-shadow: 0px 0px 0px #000000;
}
input[type=range]::-ms-fill-upper {
background: #FFE000;
border: 0px solid #FFE000;
border-radius: 14px;
box-shadow: 0px 0px 0px #000000;
}
input[type=range]::-ms-thumb {
box-shadow: 0px 0px 0px #FFE000;
border: 2px solid #FFE000;
height: 15px;
width: 15px;
border-radius: 15px;
background: #FFE000;
cursor: pointer;
}
input[type=range]:focus::-ms-fill-lower {
background: #FFE000;
}
input[type=range]:focus::-ms-fill-upper {
background: #FFE000;
}
.range {
position: relative;
display: table;
margin: 0 auto;
width: 50vw;
}
.range::before {
content: '';
display: inline-block;
vertical-align: middle;
transform: translate(100%, 0);
width: 15px;
height: 15px;
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
border-radius: 15px;
background-color: #69b6d5;
}
<div class="range">
<input type="range" name="" class="progress" value="0" max="100" min="0" />
</div>
Let me know your feedback on this. Thanks!
It's a bit hacky, but how about adding this to .range::before:
.range::before {
/* ... other css */
position: absolute;
margin-top: 11px;
}
JSFiddle
Related
How to set the outline border according to the original border which is currently rectangle on hover? I would like to set this up according to its border..
#hello {
width: 25px;
height: 10px;
background-color: red;
border-top-left-radius: 110px;
border-top-right-radius: 110px;
border: 10px solid red;
border-bottom: 0;
padding: 15px;
transform: rotate(90deg);
margin-top: 25%;
float: right;
cursor: pointer;
}
#hello:hover {
outline: 2px solid #1abc9c;
}
#hello-left {
width: 25px;
height: 10px;
background-color: red;
border-top-left-radius: 110px;
border-top-right-radius: 110px;
border: 10px solid red;
border-bottom: 0;
padding: 15px;
transform: rotate(270deg);
margin-top: 25%;
float: left;
cursor: pointer;
}
#hello-left:hover {
outline: 2px solid #1abc9c;
position: absolute;
}
<div id="hello-left"></div>
<div id="hello"></div>
Try this and you're all set...
#hello {
width: 25px;
height: 10px;
background-color: red;
border-top-left-radius: 110px;
border-top-right-radius: 110px;
border: 10px solid red;
border-bottom: 0;
padding: 15px;
transform: rotate(90deg);
margin-top: 25%;
float: right;
cursor: pointer;
}
#hello:hover {
filter: drop-shadow(0px 0px 1px #1abc9c) drop-shadow(0px 0px 1px #1abc9c) drop-shadow(0px 0px 1px #1abc9c) drop-shadow(0px 0px 1px #1abc9c);
}
#hello-left {
width: 25px;
height: 10px;
background-color: red;
border-top-left-radius: 110px;
border-top-right-radius: 110px;
border: 10px solid red;
border-bottom: 0;
padding: 15px;
transform: rotate(270deg);
margin-top: 25%;
float: left;
cursor: pointer;
}
#hello-left:hover {
filter: drop-shadow(0px 0px 1px #1abc9c) drop-shadow(0px 0px 1px #1abc9c) drop-shadow(0px 0px 1px #1abc9c) drop-shadow(0px 0px 1px #1abc9c);
}
<div id="hello-left"></div>
<div id="hello"></div>
I have a CSS styling problem: there is a difference between Firefox and Chrome browsers in the CSS styling on an HTML element.
The range element is displayed on a different height in Firefox than in Chrome. I have added two screenshots.
Firefox:
Chrome:
The range element in Chrome is pressed against the upper edge of the "content" div. And in Firefox there is a small space between the range element and the upper edge of the "content" div - as shown by the red mark.
How can I set the range element to the same height in both Firefox and Chrome? In other words: I want the range element to be vertically in the center of the "content" div.
HTML:
<div id="container">
...
<div id="content">
<input type="range" id="bar" min="0" max="100" step="1" value="0"/>
</div>
</div>
CSS:
*{
margin: 0;
padding: 0;
border: 0;
border-radius: 0;
margin-top: 0;
margin-left: 0;
margin-right: 0;
margin-bottom: 0;
}
#container {
width: 640px;
height: 372px;
background: #000;
margin: auto;
}
#content {
width: 625px;
height: 25px;
background-color: #333;
margin: auto;
text-align: center;
border-radius: 4px;
}
input[type=range] {
-webkit-appearance: none;
}
input[type=range]::-webkit-slider-runnable-track {
height: 5px;
background: #ddd;
border: none;
border-radius: 0px;
}
input[type=range]::-moz-range-track {
height: 5px;
background: #ddd;
border: none;
border-radius: 0px;
}
to style <input type="range"> properly on all browsers you need to do a lot
1. you need to hide a lot of default browser styles
input[type=range] {
-webkit-appearance: none; /* Hides the slider so that custom slider can be made */
width: 100%; /* Specific width is required for Firefox. */
background: transparent; /* Otherwise white in Chrome */
}
input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
}
input[type=range]:focus {
outline: none; /* Removes the blue border. You should probably do some kind of focus styling for accessibility reasons though. */
}
input[type=range]::-ms-track {
width: 100%;
cursor: pointer;
/* Hides the slider so custom styles can be added */
background: transparent;
border-color: transparent;
color: transparent;
}
2. then you need to style the track
input[type=range]::-webkit-slider-runnable-track {
width: 100%;
height: 8.4px;
cursor: pointer;
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
background: #3071a9;
border-radius: 1.3px;
border: 0.2px solid #010101;
}
input[type=range]:focus::-webkit-slider-runnable-track {
background: #367ebd;
}
input[type=range]::-moz-range-track {
width: 100%;
height: 8.4px;
cursor: pointer;
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
background: #3071a9;
border-radius: 1.3px;
border: 0.2px solid #010101;
}
input[type=range]::-ms-track {
width: 100%;
height: 8.4px;
cursor: pointer;
background: transparent;
border-color: transparent;
border-width: 16px 0;
color: transparent;
}
input[type=range]::-ms-fill-lower {
background: #2a6495;
border: 0.2px solid #010101;
border-radius: 2.6px;
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
}
input[type=range]:focus::-ms-fill-lower {
background: #3071a9;
}
input[type=range]::-ms-fill-upper {
background: #3071a9;
border: 0.2px solid #010101;
border-radius: 2.6px;
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
}
input[type=range]:focus::-ms-fill-upper {
background: #367ebd;
}
3. then you need to style the thumb
/* Special styling for WebKit/Blink */
input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
border: 1px solid #000000;
height: 36px;
width: 16px;
border-radius: 3px;
background: #ffffff;
cursor: pointer;
margin-top: -14px; /* You need to specify a margin in Chrome, but in Firefox and IE it is automatic */
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d; /* Add cool effects to your sliders! */
}
/* All the same stuff for Firefox */
input[type=range]::-moz-range-thumb {
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
border: 1px solid #000000;
height: 36px;
width: 16px;
border-radius: 3px;
background: #ffffff;
cursor: pointer;
}
/* All the same stuff for IE */
input[type=range]::-ms-thumb {
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
border: 1px solid #000000;
height: 36px;
width: 16px;
border-radius: 3px;
background: #ffffff;
cursor: pointer;
}
sorry copy and paste this - i edited it, now it should work
I have a question about html and css. I am trying to make an div with text---slider--text. Here is the photo of how it supposed to look.
This is my current situation.
I hope someone can help me with getting this elements on 1 line.
.information_seperator {
height: 4vh;
background-color: #ffffff;
}
.divider {
width: 50vw;
background-color: #ffc539;
margin-top: 0px;
margin-bottom: 0px;
}
.divider:after {
content: " ";
width: 5px;
height: 5px;
position: relative;
top: 0;
right: 10px;
background-color: #ffc539;
}
<div class="information_seperator">
<!--<div class="row">-->
<span class="text_info">AMS</span>
<hr class="divider">
<!--<input data-provide="slider" id="ex1" data-slider-id='ex1Slider' type="text" data-slider-min="0" data-slider-max="20" data-slider-step="1" data-slider-value="20"/>-->
<!--<span style="color: #ffc539">●</span>-->
<span>JFC</span>
<!--</div>-->
</div>
You can do this with Flexbox and JQuery UI
$('.circle').draggable({
axis: "x",
containment: ".line"
});
.slider {
display: flex;
align-items: center;
}
.line {
flex: 1;
height: 4px;
background: #FBC538;
position: relative;
margin: 0 10px;
}
.circle {
width: 20px;
height: 20px;
border-radius: 50%;
background: #FBC538;
position: absolute;
left: 0;
top: -8px;
}
span:not(.circle) {
font-size: 30px;
font-weight: bold;
font-family: Sans-serif;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<div class="slider">
<span>AMS</span>
<div class="line"><span class="circle"></span></div>
<span>JFC</span>
</div>
I think you need to read up on
display: inline-block
To align elements next to one another use : display:inline;
Example :
span,
div {
display: inline;
}
//Slider
input[type=range] {
-webkit-appearance: none;
margin: 18px 0;
width: 100%;
}
input[type=range]:focus {
outline: none;
}
input[type=range]::-webkit-slider-runnable-track {
width: 100%;
height: 8.4px;
cursor: pointer;
animate: 0.2s;
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
background: #3071a9;
border-radius: 1.3px;
border: 0.2px solid #010101;
}
input[type=range]::-webkit-slider-thumb {
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
border: 1px solid #000000;
height: 36px;
width: 16px;
border-radius: 3px;
background: #ffffff;
cursor: pointer;
-webkit-appearance: none;
margin-top: -14px;
}
input[type=range]:focus::-webkit-slider-runnable-track {
background: #367ebd;
}
input[type=range]::-moz-range-track {
width: 100%;
height: 8.4px;
cursor: pointer;
animate: 0.2s;
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
background: #3071a9;
border-radius: 1.3px;
border: 0.2px solid #010101;
}
input[type=range]::-moz-range-thumb {
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
border: 1px solid #000000;
height: 36px;
width: 16px;
border-radius: 3px;
background: #ffffff;
cursor: pointer;
}
input[type=range]::-ms-track {
width: 100%;
height: 8.4px;
cursor: pointer;
animate: 0.2s;
background: transparent;
border-color: transparent;
border-width: 16px 0;
color: transparent;
}
input[type=range]::-ms-fill-lower {
background: #2a6495;
border: 0.2px solid #010101;
border-radius: 2.6px;
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
}
input[type=range]::-ms-fill-upper {
background: #3071a9;
border: 0.2px solid #010101;
border-radius: 2.6px;
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
}
input[type=range]::-ms-thumb {
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
border: 1px solid #000000;
height: 36px;
width: 16px;
border-radius: 3px;
background: #ffffff;
cursor: pointer;
}
input[type=range]:focus::-ms-fill-lower {
background: #3071a9;
}
input[type=range]:focus::-ms-fill-upper {
background: #367ebd;
}
<span>text</span>
<div>
<input type=range />
</div>
<span>text</span>
My web page looks good in all other browsers than IE. Here the thumb of my range sliders are "cut off".
My code is here:
https://jsfiddle.net/t1pw9rh2/
HTML:
<form action="url-link-here" method="post">
<span id="mydiv">100</span>
<input class="input-range" id="sizeID" onchange="test()" oninput="test()" type="range" name="size" value="100" min="5" max="250" step ="5">
</form>
CSS:
input[type=range] {
-webkit-appearance: none;
margin: 10px 0;
width: 100%;
}
input[type=range]:focus {
outline: none;
}
input[type=range]::-webkit-slider-runnable-track {
width: 100%;
height: 10px;
cursor: pointer;
animate: 0.2s;
box-shadow: 0px 0px 0px #000000;
background: #fff;
border-radius: 1px;
border: 1px solid #39404D;
}
input[type=range]::-webkit-slider-thumb {
box-shadow: 0px 0px 0px #000000;
border: 1px solid #39404D;
height: 28px;
width: 16px;
border-radius: 2px;
background: #fff;
cursor: pointer;
-webkit-appearance: none;
margin-top: -10px;
}
input[type=range]:focus::-webkit-slider-runnable-track {
background: #fff;
}
input[type=range]::-moz-range-track {
width: 100%;
height: 10px;
cursor: pointer;
animate: 0.2s;
box-shadow: 0px 0px 0px #000000;
background: #fff;
border-radius: 1px;
border: 1px solid #39404D;
}
input[type=range]::-moz-range-thumb {
box-shadow: 0px 0px 0px #000000;
border: 1px solid #39404D;
height: 28px;
width: 16px;
border-radius: 2px;
background: #fff;
cursor: pointer;
}
input[type=range]::-ms-track {
width: 100%;
height: 10px;
cursor: pointer;
animate: 0.2s;
background: transparent;
border-color: transparent;
color: transparent;
}
input[type=range]::-ms-fill-lower {
background: #fff;
border: 1px solid #39404D;
border-radius: 4px;
box-shadow: 0px 0px 0px #000000;
}
input[type=range]::-ms-fill-upper {
background: #fff;
border: 1px solid #39404D;
border-radius: 4px;
box-shadow: 0px 0px 0px #000000;
}
input[type=range]::-ms-thumb {
box-shadow: 0px 0px 0px #000000;
border: 1px solid #39404D;
height: 28px;
width: 16px;
border-radius: 2px;
background: #fff;
cursor: pointer;
}
input[type=range]:focus::-ms-fill-lower {
background: #fff;
}
input[type=range]:focus::-ms-fill-upper {
background: #fff;
}
Javascript:
function test(){
var myDivElem = document.getElementById("mydiv");
var sizerange= document.getElementById("sizeID");
myDivElem.innerHTML = sizerange.value;
}
My web page can be seen here:
http://negoto.azurewebsites.net/
How do I fix the css so the thumb looks good in IE?
Best, Peter
I found the answer here. http://brennaobrien.com/blog/2014/05/style-input-type-range-in-every-browser.html
It mentions you cant style the thumb bigger than the track in IE.
When we use input range <input type="range", there is a handler which is moveable as how we handle it.
Now I need a help how to customize this handle, in this case I want to change the default handler with my own handler(image of button).
Thanks for the help
<input type='range'/>
Use the following to style the base:
input[type=range] {
-webkit-appearance: none; /* Hides the slider so that custom slider can be made */
width: 100%; /* Specific width is required for Firefox. */
}
input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
}
input[type=range]:focus {
outline: none; /* Removes the blue border. You should probably do some kind of focus styling for accessibility reasons though. */
}
input[type=range]::-ms-track {
width: 100%;
cursor: pointer;
background: transparent; /* Hides the slider so custom styles can be added */
border-color: transparent;
color: transparent;
}
Use the following to style the thumb:
/* Special styling for WebKit/Blink */
input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
border: 1px solid #000000;
height: 36px;
width: 16px;
border-radius: 3px;
background: #ffffff;
cursor: pointer;
margin-top: -14px; /* You need to specify a margin in Chrome, but in Firefox and IE it is automatic */
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d; /* Add cool effects to your sliders! */
}
/* All the same stuff for Firefox */
input[type=range]::-moz-range-thumb {
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
border: 1px solid #000000;
height: 36px;
width: 16px;
border-radius: 3px;
background: #ffffff;
cursor: pointer;
}
/* All the same stuff for IE */
input[type=range]::-ms-thumb {
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
border: 1px solid #000000;
height: 36px;
width: 16px;
border-radius: 3px;
background: #ffffff;
cursor: pointer;
}
Snippet:
input[type=range] {
-webkit-appearance: none;
margin: 10px 0;
width: 100%;
}
input[type=range]:focus {
outline: none;
}
input[type=range]::-webkit-slider-runnable-track {
width: 100%;
height: 12.8px;
cursor: pointer;
animate: 0.2s;
box-shadow: 0px 0px 0px #000000, 0px 0px 0px #0d0d0d;
background: #ac51b5;
border-radius: 25px;
border: 0px solid #000101;
}
input[type=range]::-webkit-slider-thumb {
box-shadow: 0px 0px 0px #000000, 0px 0px 0px #0d0d0d;
border: 0px solid #000000;
height: 20px;
width: 39px;
border-radius: 7px;
background: #65001c;
cursor: pointer;
-webkit-appearance: none;
margin-top: -3.6px;
}
input[type=range]:focus::-webkit-slider-runnable-track {
background: #ac51b5;
}
input[type=range]::-moz-range-track {
width: 100%;
height: 12.8px;
cursor: pointer;
animate: 0.2s;
box-shadow: 0px 0px 0px #000000, 0px 0px 0px #0d0d0d;
background: #ac51b5;
border-radius: 25px;
border: 0px solid #000101;
}
input[type=range]::-moz-range-thumb {
box-shadow: 0px 0px 0px #000000, 0px 0px 0px #0d0d0d;
border: 0px solid #000000;
height: 20px;
width: 39px;
border-radius: 7px;
background: #65001c;
cursor: pointer;
}
input[type=range]::-ms-track {
width: 100%;
height: 12.8px;
cursor: pointer;
animate: 0.2s;
background: transparent;
border-color: transparent;
border-width: 39px 0;
color: transparent;
}
input[type=range]::-ms-fill-lower {
background: #ac51b5;
border: 0px solid #000101;
border-radius: 50px;
box-shadow: 0px 0px 0px #000000, 0px 0px 0px #0d0d0d;
}
input[type=range]::-ms-fill-upper {
background: #ac51b5;
border: 0px solid #000101;
border-radius: 50px;
box-shadow: 0px 0px 0px #000000, 0px 0px 0px #0d0d0d;
}
input[type=range]::-ms-thumb {
box-shadow: 0px 0px 0px #000000, 0px 0px 0px #0d0d0d;
border: 0px solid #000000;
height: 20px;
width: 39px;
border-radius: 7px;
background: #65001c;
cursor: pointer;
}
input[type=range]:focus::-ms-fill-lower {
background: #ac51b5;
}
input[type=range]:focus::-ms-fill-upper {
background: #ac51b5;
}
body {
padding: 30px;
}
<input type="range" />
Reference: Styling Cross-Browser Compatible Range Inputs with CSS