Reputation: 2634
I'm using CSS3 to style a checkbox like this site (Slide THREE)
html:
<div class="slideThree">
<input type="checkbox" id="slideThree" name="check" />
<label for="slideThree"></label>
</div>
css:
input[type=checkbox] {
visibility: hidden;
}
/* SLIDE THREE */
.slideThree {
width: 91px;
height: 26px;
background: #2B3D61;
margin: 5px;
-webkit-border-radius: 50px;
-moz-border-radius: 50px;
border-radius: 50px;
position: relative;
-webkit-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,0.2);
-moz-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,0.2);
box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,0.2);
}
.slideThree:after {
content: 'OFF';
font: 14px/26px Arial, sans-serif;
color: #FFF;
position: absolute;
right: 10px;
z-index: 0;
font-weight: bold;
text-shadow: 1px 1px 0px rgba(255,255,255,.15);
}
.slideThree:before {
content: 'ON';
font: 14px/26px Arial, sans-serif;
color: #FFF;
position: absolute;
left: 10px;
z-index: 0;
font-weight: bold;
}
.slideThree label {
display: block;
width: 45px;
height: 24px;
-webkit-border-radius: 50px;
-moz-border-radius: 50px;
border-radius: 50px;
-webkit-transition: all .4s ease;
-moz-transition: all .4s ease;
-o-transition: all .4s ease;
-ms-transition: all .4s ease;
transition: all .4s ease;
cursor: pointer;
position: absolute;
top: 1px;
left: 3px;
z-index: 1;
-webkit-box-shadow: 0px 2px 5px 0px rgba(0,0,0,0.3);
-moz-box-shadow: 0px 2px 5px 0px rgba(0,0,0,0.3);
box-shadow: 0px 2px 5px 0px rgba(0,0,0,0.3);
background: #fcfff4;
background: -webkit-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
background: -moz-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
background: -o-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
background: -ms-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
background: linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fcfff4', endColorstr='#b3bead',GradientType=0 );
}
.slideThree input[type=checkbox]:checked + label {
left: 44px;
}
IE8 doesn't support something here. EDIT I've have a DOCTYPE
and I've removed z-index
but that changed nothing. Checkbox still doesn't work. Is there a way to get around this or do I need to use conditional css in my html? If it degrades to just a simple checkbox would be fine for IE8.
Upvotes: 0
Views: 2385
Reputation: 8508
Add a span before the label and after the label:
<label for="slideThree"></label><span class="on">On</span><span class="off">Off</span>
CSS for .on:
font: 14px/26px Arial, sans-serif;
color: #FFF;
position: absolute;
left: 10px;
z-index: 0;
font-weight: bold;
CSS for .off:
font: 14px/26px Arial, sans-serif;
color: #FFF;
position: absolute;
right: 10px;
z-index: 0;
font-weight: bold;
text-shadow: 1px 1px 0px rgba(255,255,255,.15);
Upvotes: 0
Reputation: 2634
I went with the dirty (and I mean Vegas dirty) IE conditional to overwrite the css to get it back down to just a checkbox.
aka
<!--[if lt IE 9]> <link rel="stylesheet" href="default-ie.css" type="text/css" /> <![endif]-->
Upvotes: 0
Reputation: 114407
The way to get around this is to create an additional classname for the :after
and :before
declarations and use JavaScript to add/remove these classes based on events.
Upvotes: 1