iOS like toggle button using checkbox looks different for different browsers - html

I am kinda new to web designing. Trying to create a toggle iOS like button but the issue is with its appearance on different browsers. It looks different in different browsers. As I tested it it works properly on Chrome.
Can somebody help me to make it look same on all browsers? Sorry for the broken english?
jsfiddle Link : http://jsfiddle.net/racy2408/Let1y8yr/
Given below is CSS I tried:
body {
margin: 30px;
text-align: center;
}
input[type=checkbox],
input[type=radio] {
display: inline-block;
width: 50px;
height: 30px;
position: relative;
cursor: pointer;
appearance: none;
-webkit-appearance: none;
-moz-appearance: none;
box-shadow: inset 0px 5px 40px -13px rgba(0, 0, 0, 0.75);
-webkit-box-shadow: inset 0px 5px 40px -13px rgba(0, 0, 0, 0.75);
-moz-box-shadow: inset 0px 5px 40px -13px rgba(0, 0, 0, 0.75);
-o-box-shadow: inset 0px 5px 40px -13px rgba(0, 0, 0, 0.75);
border-radius: 15px;
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
-o-border-radius: 15px;
background-color: #fff;
padding: 1px;
margin: 0px;
transition: all 0.3s ease-out;
-webkit-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
transform: scale(1);
-webkit-transform: scale(1);
/*Adjust size here*/
-moz-transform: scale(1);
-o-transform: scale(1);
}
input[type=checkbox]:checked,
input[type=radio]:checked {
box-shadow: inset 0px 0px 0px 20px #53d76a, inset 0px 5px 40px -13px rgba(132, 132, 132, 1);
-webkit-box-shadow: inset 0px 0px 0px 20px #53d76a, inset 0px 5px 40px -13px rgba(132, 132, 132, 1);
-moz-box-shadow: inset 0px 0px 0px 20px #53d76a, inset 0px 5px 40px -13px rgba(132, 132, 132, 1);
-o-box-shadow: inset 0px 0px 0px 20px #53d76a, inset 0px 5px 40px -13px rgba(132, 132, 132, 1);
}
input[type=checkbox]:after,
input[type=radio]:after {
content: " ";
position: absolute;
width: 28px;
height: 28px;
cursor: pointer;
border-radius: 15px;
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
-o-border-radius: 15px;
box-shadow: 0px 2px 2px 1px rgba(0, 0, 0, 0.2);
-webkit-box-shadow: 0px 2px 2px 1px rgba(0, 0, 0, 0.2);
-moz-box-shadow: 0px 2px 2px 1px rgba(0, 0, 0, 0.2);
-o-box-shadow: 0px 2px 2px 1px rgba(0, 0, 0, 0.2);
background-color: #fff;
/* background-image: url(../images/toggle.png);
background-repeat: no-repeat;
background-size: contain; */
transition: all 0.2s ease-in 0.2s;
-webkit-transition: all 0.2s ease-in 0.2s;
-moz-transition: all 0.2s ease-in 0.2s;
-o-transition: all 0.2s ease-in 0.2s;
}
input[type="checkbox"]:checked:after,
input[type="radio"]:checked:after {
left: 23px;
}
input[type=checkbox]:focus,
input[type=checkbox]:active,
input[type=radio]:focus,
input[type=radio]:active {
outline: 0;
}
<h1>Checkbox :</h1>
<input type="checkbox" />
<input type="checkbox" checked />
<h1>Radio :</h1>
<input type="radio" name="group" />
<input type="radio" name="group" checked />
<input type="radio" name="group" />

inputs aren't supposed to be able to add before and after psuedo-elements because they aren't containers (e.g. an <input> can't have child elements).
There is some more information in the comment here: https://stackoverflow.com/a/4660434/4338477
You could add labels to get the same effect though (this works in Firefox and IE9+):
http://jsfiddle.net/8okjwLxx/2/
<h1>Checkbox :</h1>
<input id="checkbox1" type="checkbox" />
<label for="checkbox1"></label>
<input id="checkbox2" type="checkbox" checked />
<label for="checkbox2"></label>
<h1>Radio :</h1>
<input id="radio1" type="radio" name="group" />
<label for="radio1"></label>
<input id="radio2" type="radio" name="group" checked />
<label for="radio2"></label>
<input id="radio3" type="radio" name="group" />
<label for="radio3"></label>
body {
margin: 30px;
text-align: center;
}
input[type=checkbox],
input[type=radio]{
display: none;
}
input[type=checkbox] + label,
input[type=radio] + label {
display: inline-block;
width: 50px;
height: 30px;
position: relative;
cursor: pointer;
appearance: none;
-webkit-appearance: none;
-moz-appearance: none;
box-shadow: inset 0px 5px 40px -13px rgba(0, 0, 0, 0.75);
-webkit-box-shadow: inset 0px 5px 40px -13px rgba(0, 0, 0, 0.75);
-moz-box-shadow: inset 0px 5px 40px -13px rgba(0, 0, 0, 0.75);
-o-box-shadow: inset 0px 5px 40px -13px rgba(0, 0, 0, 0.75);
border-radius: 15px;
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
-o-border-radius: 15px;
background-color: #fff;
padding: 1px;
margin: 0px;
transition: all 0.3s ease-out;
-webkit-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
transform: scale(1);
-webkit-transform: scale(1); /*Adjust size here*/
-moz-transform: scale(1);
-o-transform: scale(1);
}
input[type=checkbox]:checked + label,
input[type=radio]:checked + label {
box-shadow: inset 0px 0px 0px 20px #53d76a, inset 0px 5px 40px -13px rgba(132, 132, 132, 1);
-webkit-box-shadow: inset 0px 0px 0px 20px #53d76a, inset 0px 5px 40px -13px rgba(132, 132, 132, 1);
-moz-box-shadow: inset 0px 0px 0px 20px #53d76a, inset 0px 5px 40px -13px rgba(132, 132, 132, 1);
-o-box-shadow: inset 0px 0px 0px 20px #53d76a, inset 0px 5px 40px -13px rgba(132, 132, 132, 1);
}
input[type=checkbox] + label:after,
input[type=radio] + label:after {
left: 0;
content: " ";
position: absolute;
width: 28px;
height: 28px;
cursor: pointer;
border-radius: 15px;
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
-o-border-radius: 15px;
box-shadow: 0px 2px 2px 1px rgba(0, 0, 0, 0.2);
-webkit-box-shadow: 0px 2px 2px 1px rgba(0, 0, 0, 0.2);
-moz-box-shadow: 0px 2px 2px 1px rgba(0, 0, 0, 0.2);
-o-box-shadow: 0px 2px 2px 1px rgba(0, 0, 0, 0.2);
background-color: #fff;
/* background-image: url(../images/toggle.png);
background-repeat: no-repeat;
background-size: contain; */
transition: all 0.2s ease-in 0.2s;
-webkit-transition: all 0.2s ease-in 0.2s;
-moz-transition: all 0.2s ease-in 0.2s;
-o-transition: all 0.2s ease-in 0.2s;
}
input[type=checkbox]:checked + label:after,
input[type=radio]:checked + label:after {
left: 23px;
}
input[type=checkbox]:focus,
input[type=checkbox]:active,
input[type=radio]:focus,
input[type=radio]:active {
outline: 0;
}

Related

Html/Css flickering when i hover over a button

i've been looking for some solutions here but i seem to stupid to change it the way i need to, so i decided to make a post.
Following problem:
button {
font-family: custom-bold;
width: 100%;
font-size: 1.1rem;
outline: none;
padding: 10px;
background-color: rgba(0, 0, 0, 0.322);
border: none;
border-radius: 5px;
color: white;
box-shadow: 3px 3px 3px 3px rgba(0, 0, 0, 0.5);
text-shadow: 3px 3px 3px 3px rgba(0, 0, 0, 0.5);
}
button:hover {
background-color:rgb(255, 255, 255);
display: inline-block;
transform: perspective(1px) translateZ(0);
transform: perspective(1px) translateZ(0);
box-shadow: 0 0 1px rgba(0, 0, 0, 0);
position: relative;
overflow: hidden;
transition-property: color;
transition-duration: 0.5s;
color:rgb(0, 0, 0);
}
<button>thatsabutton</button>
when u hover over it, it flickers. When for example i add a margin-top to it with 1%, i would prevent the flickering but it would fk over with the other things i've made. Any idea what i can do it to prvent it with out adding margin to it? Regards!
You are only transitioning the color, change it to 'all' and you're OK.
Also add it to the button class for the reverse action.
button {
font-family: custom-bold;
width: 100%;
font-size: 1.1rem;
outline: none;
padding: 10px;
background-color: rgba(0, 0, 0, 0.322);
border: none;
border-radius: 5px;
color: white;
box-shadow: 3px 3px 3px 3px rgba(0, 0, 0, 0.5);
text-shadow: 3px 3px 3px 3px rgba(0, 0, 0, 0.5);
transition-property: all;
transition-duration: 0.5s;
}
button:hover {
background-color:rgb(255, 255, 255);
display: inline-block;
transform: perspective(1px) translateZ(0);
transform: perspective(1px) translateZ(0);
box-shadow: 0 0 1px rgba(0, 0, 0, 0);
position: relative;
overflow: hidden;
transition-property: all;
transition-duration: 0.5s;
color:rgb(0, 0, 0);
}
<button>thatsabutton</button>

HTML Class reference

I've a little problem with this code.
My css class has the name:
section.border button
From what I would like to create a href with the look of < button >
<a data-scroll href="#link" class="section border button">Go to</a>
This method unfortunately isn't working.
<section class="border">
<button>Click</button> <- it's OK
<a data-scroll href="#test" class="section border button">Go to Google</a> <- NOPE
</section>
CSS
section.border button {
color: #f6f6f6;
background: rgba(0,0,0,0);
border: solid 2px #f6f6f6;
padding:10px 40px 10px 40px;
text-transform: uppercase;
display: inline-block;
vertical-align: middle;
-webkit-transform: translateZ(0);
transform: translateZ(0);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-moz-osx-font-smoothing: grayscale;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
-webkit-transition-property: box-shadow;
transition-property: box-shadow;
-webkit-transition-property: background-color;
transition-property: background-color;
font-size: 1.0em;
font-family: "Lato";
text-transform: uppercase;
text-shadow: 0px 2px 0px rgba(0, 0, 0, 0.4), 0px 2px 2px rgba(0, 0, 0, 0.3);
-moz-box-shadow: box-shadow: 0 0 12px 2px rgba(0, 0, 0, 0.2);
-webkit-box-shadow: box-shadow: 0 0 12px 2px rgba(0, 0, 0, 0.2);
box-shadow: 0 0 12px 2px rgba(0, 0, 0, 0.2);
/* Hack to improve aliasing on mobile/tablet devices */
}
section.border button:hover,
section.border button.hover,section.border button:active,
section.border button.active {
border-color: white;
background-color: rgba(187,187,187, 0.3);
text-shadow: 0px 2px 0px rgba(0, 0, 0, 0.4), 0px 2px 2px rgba(0, 0, 0, 0.3);
box-shadow: 0 0 12px 2px rgba(0, 0, 0, 0.2);
}
Simply use a custom css name, and add it to every items you want to show as a button.
section.border button, .myButton { ... }
<section class="border">
<button>Click</button>
<a class="myButton">Go to Google</a>
</section>
<a class="myButton">Go to Bing</a>
Go to Google
does't match any of those css rules.
The css rule is for a button inside a section that has a border class
<section class="border">
<button >Go to Google</button>
</section>

strange css error on focus

I found this example since this style in good so i inserted in my project
following example is search box in html & css
ERROR only in chrome, safari
works good in firefox
when i click(focus) on search box it works as styled but a blue border line appear when clicked i don't want the blue border when i click on input box i tried remove shadow still no success
.wrap{position: absolute;
text-align: center;
top: 50%;
-webkit-transform: translate(0%,-50%);
-moz-transform: translate(0%,-50%);
transform: translate(0%,-50%);}
.se {
margin-left:50px;
}
#search input[type="text"] {
background: url(search-white.png) no-repeat 10px 6px #444;
border: 0 none;
font: bold 12px Arial,Helvetica,Sans-serif;
color: #d7d7d7;
width:150px;
padding: 6px 15px 6px 35px;
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
text-shadow: 0 2px 2px rgba(0, 0, 0, 0.3);
-webkit-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 3px rgba(0, 0, 0, 0.2) inset;
-moz-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 3px rgba(0, 0, 0, 0.2) inset;
box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 3px rgba(0, 0, 0, 0.2) inset;
-webkit-transition: all 0.7s ease 0s;
-moz-transition: all 0.7s ease 0s;
-o-transition: all 0.7s ease 0s;
transition: all 0.7s ease 0s;
}
#search input[type="text"]:focus {
background: url(search-dark.png) no-repeat 10px 6px #fcfcfc;
color: #6a6f75;
width: 200px;
-webkit-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 rgba(0, 0, 0, 0.5) inset;
-moz-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 rgba(0, 0, 0, 0.5) inset;
box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 rgba(0, 0, 0, 0.5) inset;
text-shadow: 0 2px 3px rgba(0, 0, 0, 0.1);
}
<div class="wrap se">
<form method="get" action="/search" id="search">
<input name="q" type="text" size="40" placeholder="Search..." />
</form>
</div>
set outline: none on the input to remove chrome's input highlighting
#search input[type="text"]{
outline: none;
}
FIDDLE

Overwriting Bootstrap CSS

So in my bootstrap.css I have:
.form-control {
display: block;
width: 100%;
height: 34px;
padding: 6px 12px;
font-size: 14px;
line-height: 1.428571429;
color: #555555;
vertical-align: middle;
background-color: #ffffff;
border: 1px solid #cccccc;
border-radius: 4px;
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
-webkit-transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s;
transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s;
}
And in my own .css file that I loaded after bootstrap.css:
.form-control {
display: block;
width: 100%;
height: 45px;
padding: 6px 12px;
font-size: 27px;
line-height: 1.928571429;
color: #555555;
vertical-align: left;
background-color: #002b36;
border: 0px none #002b36;
border-radius: 4px;
-webkit-box-shadow: none 0 0px 1px rgba(0, 0, 0, 0.075);
box-shadow: none 0 0px 1px rgba(0, 0, 0, 0.075);
-webkit-transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s;
transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s;
}
Everything is overwritten except for the
-webkit-box-shadow: none 0 0px 1px rgba(0, 0, 0, 0.075);
box-shadow: none 0 0px 1px rgba(0, 0, 0, 0.075);
I can tell since if I change that snippet in bootstrap.css to match what I have in my own css file that it actually changes on the webpage. So for some reason, my own css overwrites everything except for those two lines about box-shadows, and I don't know why.
Try shorten it to valid CSS like:
-webkit-box-shadow: none;
box-shadow: none;

Removing the border on select tag

I made a form for a site and all textboxes have rounded corners except the select drop down box. I made a rounded box style and it shows but the original square also shows behind it. Is there any way I can remove this so my is the only one that shows. I'll add the code
<td>Service Requested:
<select style="margin-left: 10px" name="service" tabindex="4">
<option value=" " selected="selected"> </option>
<option value="Residential Move">Residential Move*</option>
<option value="Commercial Move">Commercial Move*</option>
<option value="Storage Unit Loading">Storage Unit Loading</option>
<option value="Storage Unit Unloading">Storage Unit Unloading</option>
<option value="Furniture Consignment">Furniture Consignment</option>
<option value="Assembly/Removal">Assembly/Removal</option>
<option value="Landscaping">Landscaping</option>
<option value="Cleanout">Cleanout</option>
<option value="General Help">General Help</option>
</select>
</td>
and this is the entire css for the whole form. Just have at it
#searchbox {
padding-left: 190px;
padding-bottom:40px;
background: url(../images/border-dashed.gif) repeat-x left bottom;
}
#searchbox form {
margin: 0;
}
#searchbox table {
margin: 0;
}
#searchbox th, td {
text-align: left;
font-weight: normal;
color:#302f2f;
}
#searchbox .submitrow {
text-align: right;
}
#search {
}
#search input[type="text"] {
border: 2px solid #c1c2c3 ;
font: bold 12px Arial,Helvetica,Sans-serif;
color: #302f2f;
width: 100px;
padding: 6px 15px 6px 15px;
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
text-shadow: 0 2px 3px rgba(0, 0, 0, 0.1);
-webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15) inset;
-moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15) inset;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15) inset;
-webkit-transition: all 0.7s ease 0s;
-moz-transition: all 0.7s ease 0s;
-o-transition: all 0.7s ease 0s;
transition: all 0.7s ease 0s;
}
#search input[type="text"]:focus {
width: 150px;
}
#search select {
border: 2px solid #c1c2c3 ;
font: bold 12px Arial,Helvetica,Sans-serif;
color: #302f2f;
width: 200px;
padding: 6px 15px 6px 15px;
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
text-shadow: 0 2px 3px rgba(0, 0, 0, 0.1);
-webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15) inset;
-moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15) inset;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15) inset;
-webkit-transition: all 0.7s ease 0s;
-moz-transition: all 0.7s ease 0s;
-o-transition: all 0.7s ease 0s;
transition: all 0.7s ease 0s;
}
#search select:focus {
width: 250px;
}
#search textarea {
border: 2px solid #c1c2c3 ;
font: bold 12px Arial,Helvetica,Sans-serif;
color: #302f2f;
width: 300px;
padding: 6px 15px 6px 15px;
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
text-shadow: 0 2px 3px rgba(0, 0, 0, 0.1);
-webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15) inset;
-moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15) inset;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15) inset;
-webkit-transition: all 0.7s ease 0s;
-moz-transition: all 0.7s ease 0s;
-o-transition: all 0.7s ease 0s;
transition: all 0.7s ease 0s;
}
#search textarea:focus {
}
.contactwrapper {width:auto; height:200px; overflow:hidden;}
.extra-wrap {width:800px; overflow:hidden;}
.formbtn {
background: url(../images/formbtns.png) no-repeat;
background-position: 0 bottom;
color: #f1f2ea;
display: block;
line-height: 28px;
float:right;
margin-left:450px;
margin-bottom:40px;
height: 30px;
width: 100px;
margin: 48px 10px;
outline: 0;
text-align: center;
text-decoration: none;
}
.formbtn:hover {
background-position: 0 top;
}
thanks
The ability to style select boxes is inconsistent across browsers. Some of them respond well to CSS styling and some don't, but if you really want to have completely consistent control over it and its behavior, you need to make a faux-select that is powered by javascript.
Check out the Select2 control, it's nice.
Styling to a select box is chosen mostly by the browser and is not very customizable without javascript besides using a background image.
Since jQuery UI 1.8 there has been an autocomplete control that has a combobox functionality which replaces a select control.
I found an alternative, but not sure how it will behave with all browsers. But if you change the border property to inherit it will do it. At least in Chrome
border: 2px inherit #c1c2c3 ;