Skip to main content
Moved HTML/CSS to code snippet.
Source Link
Vadim Ovchinnikov
  • 14.1k
  • 7
  • 68
  • 95

You can style checkboxscheckboxes with a little trickery using the labellabel element an example is below:


The CSS


.checkbox > input[type=checkbox] { visibility: hidden; } .checkbox { position: relative; display: block; width: 80px; height: 26px; margin: 0 auto; background: #FFF; border: 1px solid #2E2E2E; border-radius: 2px; -webkit-border-radius: 2px; -moz-border-radius: 2px; } .checkbox:after { position: absolute; display: inline; right: 10px; content: 'no'; color: #E53935; font: 12px/26px Arial, sans-serif; font-weight: bold; text-transform: capitalize; z-index: 0; } .checkbox:before { position: absolute; display: inline; left: 10px; content: 'yes'; color: #43A047; font: 12px/26px Arial, sans-serif; font-weight: bold; text-transform: capitalize; z-index: 0; } .checkbox label { position: absolute; display: block; top: 3px; left: 3px; width: 34px; height: 20px; background: #2E2E2E; cursor: pointer; transition: all 0.5s linear; -webkit-transition: all 0.5s linear; -moz-transition: all 0.5s linear; border-radius: 2px; -webkit-border-radius: 2px; -moz-border-radius: 2px; z-index: 1; } .checkbox input[type=checkbox]:checked + label { left: 43px; } 

The HTML


<div class="checkbox"> <input id="checkbox1" type="checkbox" value="1" /> <label for="checkbox1"></label> </div> 
.checkbox > input[type=checkbox] { visibility: hidden; } .checkbox { position: relative; display: block; width: 80px; height: 26px; margin: 0 auto; background: #FFF; border: 1px solid #2E2E2E; border-radius: 2px; -webkit-border-radius: 2px; -moz-border-radius: 2px; } .checkbox:after { position: absolute; display: inline; right: 10px; content: 'no'; color: #E53935; font: 12px/26px Arial, sans-serif; font-weight: bold; text-transform: capitalize; z-index: 0; } .checkbox:before { position: absolute; display: inline; left: 10px; content: 'yes'; color: #43A047; font: 12px/26px Arial, sans-serif; font-weight: bold; text-transform: capitalize; z-index: 0; } .checkbox label { position: absolute; display: block; top: 3px; left: 3px; width: 34px; height: 20px; background: #2E2E2E; cursor: pointer; transition: all 0.5s linear; -webkit-transition: all 0.5s linear; -moz-transition: all 0.5s linear; border-radius: 2px; -webkit-border-radius: 2px; -moz-border-radius: 2px; z-index: 1; } .checkbox input[type=checkbox]:checked + label { left: 43px; }
<div class="checkbox"> <input id="checkbox1" type="checkbox" value="1" /> <label for="checkbox1"></label> </div>

  

You can style checkboxs with a little trickery using the label element an example is below:


The CSS


.checkbox > input[type=checkbox] { visibility: hidden; } .checkbox { position: relative; display: block; width: 80px; height: 26px; margin: 0 auto; background: #FFF; border: 1px solid #2E2E2E; border-radius: 2px; -webkit-border-radius: 2px; -moz-border-radius: 2px; } .checkbox:after { position: absolute; display: inline; right: 10px; content: 'no'; color: #E53935; font: 12px/26px Arial, sans-serif; font-weight: bold; text-transform: capitalize; z-index: 0; } .checkbox:before { position: absolute; display: inline; left: 10px; content: 'yes'; color: #43A047; font: 12px/26px Arial, sans-serif; font-weight: bold; text-transform: capitalize; z-index: 0; } .checkbox label { position: absolute; display: block; top: 3px; left: 3px; width: 34px; height: 20px; background: #2E2E2E; cursor: pointer; transition: all 0.5s linear; -webkit-transition: all 0.5s linear; -moz-transition: all 0.5s linear; border-radius: 2px; -webkit-border-radius: 2px; -moz-border-radius: 2px; z-index: 1; } .checkbox input[type=checkbox]:checked + label { left: 43px; } 

The HTML


<div class="checkbox"> <input id="checkbox1" type="checkbox" value="1" /> <label for="checkbox1"></label> </div> 

 

You can style checkboxes with a little trickery using the label element an example is below:

.checkbox > input[type=checkbox] { visibility: hidden; } .checkbox { position: relative; display: block; width: 80px; height: 26px; margin: 0 auto; background: #FFF; border: 1px solid #2E2E2E; border-radius: 2px; -webkit-border-radius: 2px; -moz-border-radius: 2px; } .checkbox:after { position: absolute; display: inline; right: 10px; content: 'no'; color: #E53935; font: 12px/26px Arial, sans-serif; font-weight: bold; text-transform: capitalize; z-index: 0; } .checkbox:before { position: absolute; display: inline; left: 10px; content: 'yes'; color: #43A047; font: 12px/26px Arial, sans-serif; font-weight: bold; text-transform: capitalize; z-index: 0; } .checkbox label { position: absolute; display: block; top: 3px; left: 3px; width: 34px; height: 20px; background: #2E2E2E; cursor: pointer; transition: all 0.5s linear; -webkit-transition: all 0.5s linear; -moz-transition: all 0.5s linear; border-radius: 2px; -webkit-border-radius: 2px; -moz-border-radius: 2px; z-index: 1; } .checkbox input[type=checkbox]:checked + label { left: 43px; }
<div class="checkbox"> <input id="checkbox1" type="checkbox" value="1" /> <label for="checkbox1"></label> </div>
 

improved code
Source Link
TURTLE
  • 3.9k
  • 4
  • 54
  • 55

You can style checkboxs with a little trickery using the label element an example is below:


The CSS


.checkbox > input[type=checkbox] { visibility: hidden; } .checkbox { widthposition: 80px;relative; heightdisplay: 26px;block; marginwidth: auto;80px; positionheight: relative;26px;   margin: 0 auto; background: #FFF; border: 1px solid #2E2E2E; border-radius: 2px; -webkit-border-radius: 2px; -moz-border-radius: 2px; } .checkbox:after { contentposition: 'No';absolute; fontdisplay: 12px/26pxinline;  Arial, sans-serif; right: 10px; content: 'no'; color: #B50000;#E53935; positionfont: absolute;12px/26px Arial, sans-serif; rightfont-weight: 10px;bold; ztext-indextransform: 0;capitalize; fontz-weightindex: bold;0; } .checkbox:before { contentposition: 'Yes';absolute; fontdisplay: 12px/26pxinline;  Arial, sans-serif; left: 10px; content: 'yes'; color: #00BF00;#43A047; positionfont: absolute;12px/26px Arial, sans-serif; leftfont-weight: 10px;bold; ztext-indextransform: 0;capitalize; fontz-weightindex: bold;0; } .checkbox label { displayposition: block;absolute; widthdisplay: 34px;block; heighttop: 20px;3px; positionleft: absolute;3px; topwidth: 3px;34px; leftheight: 3px;20px; z-indexbackground: 1;#2E2E2E; backgroundcursor: #2E2E2E;pointer; transition: all 0.5s linear; -webkit-transition: all 0.5s linear; -moz-transition: all 0.5s linear; cursor: pointer; border-radius: 2px; -webkit-border-radius: 2px; -moz-border-radius: 2px;  z-index: 1; } .checkbox input[type=checkbox]:checked + label { left: 43px; } 

The HTML


<div class="checkbox"> <input id="checkbox1" type="checkbox" value="1" id="checkbox1" name="check"/> <label for="checkbox1"></label> </div> 

And a FIDDLEFIDDLE for the above code. Note that some CSS doesn't work in older versions of browsers, but I'm sure there are some fancy JavaScript examples out there!

You can style checkboxs with the label element an example is below:


The CSS


.checkbox input[type=checkbox] { visibility: hidden; } .checkbox { width: 80px; height: 26px; margin: auto; position: relative; background: #FFF; border: 1px solid #2E2E2E; border-radius: 2px; -webkit-border-radius: 2px; -moz-border-radius: 2px; } .checkbox:after { content: 'No'; font: 12px/26px Arial, sans-serif; color: #B50000; position: absolute; right: 10px; z-index: 0; font-weight: bold; } .checkbox:before { content: 'Yes'; font: 12px/26px Arial, sans-serif; color: #00BF00; position: absolute; left: 10px; z-index: 0; font-weight: bold; } .checkbox label { display: block; width: 34px; height: 20px; position: absolute; top: 3px; left: 3px; z-index: 1; background: #2E2E2E; transition: all 0.5s linear; -webkit-transition: all 0.5s linear; -moz-transition: all 0.5s linear; cursor: pointer; border-radius: 2px; -webkit-border-radius: 2px; -moz-border-radius: 2px; } .checkbox input[type=checkbox]:checked + label { left: 43px; } 

The HTML


<div class="checkbox"> <input type="checkbox" value="1" id="checkbox1" name="check"/> <label for="checkbox1"></label> </div> 

And a FIDDLE for the above code. Note that some CSS doesn't work in older versions of browsers, but I'm sure there are some fancy JavaScript examples out there!

You can style checkboxs with a little trickery using the label element an example is below:


The CSS


.checkbox > input[type=checkbox] { visibility: hidden; } .checkbox { position: relative; display: block; width: 80px; height: 26px;   margin: 0 auto; background: #FFF; border: 1px solid #2E2E2E; border-radius: 2px; -webkit-border-radius: 2px; -moz-border-radius: 2px; } .checkbox:after { position: absolute; display: inline;   right: 10px; content: 'no'; color: #E53935; font: 12px/26px Arial, sans-serif; font-weight: bold; text-transform: capitalize; z-index: 0; } .checkbox:before { position: absolute; display: inline;   left: 10px; content: 'yes'; color: #43A047; font: 12px/26px Arial, sans-serif; font-weight: bold; text-transform: capitalize; z-index: 0; } .checkbox label { position: absolute; display: block; top: 3px; left: 3px; width: 34px; height: 20px; background: #2E2E2E; cursor: pointer; transition: all 0.5s linear; -webkit-transition: all 0.5s linear; -moz-transition: all 0.5s linear; border-radius: 2px; -webkit-border-radius: 2px; -moz-border-radius: 2px;  z-index: 1; } .checkbox input[type=checkbox]:checked + label { left: 43px; } 

The HTML


<div class="checkbox"> <input id="checkbox1" type="checkbox" value="1" /> <label for="checkbox1"></label> </div> 

And a FIDDLE for the above code. Note that some CSS doesn't work in older versions of browsers, but I'm sure there are some fancy JavaScript examples out there!

fixed grammar
Source Link
TURTLE
  • 3.9k
  • 4
  • 54
  • 55

You can style checkboxs with lablethe label element an example is below:


The css!CSS


.checkbox input[type=checkbox] { visibility: hidden; } .checkbox { width: 80px; height: 26px; margin: auto; position: relative; background: #fff;#FFF; border: 1px solid #2e2e2e;#2E2E2E; border-radius: 2px; -webkit-border-radius: 2px; -moz-border-radius: 2px; } .checkbox:after { content: 'No'; font: 12px/26px Arial, sans-serif; color: #b50000;#B50000; position: absolute; right: 10px; z-index: 0; font-weight: bold; } .checkbox:before { content: 'Yes'; font: 12px/26px Arial, sans-serif; color: #00bf00;#00BF00; position: absolute; left: 10px; z-index: 0; font-weight: bold; } .checkbox label { display: block; width: 34px; height: 20px; position: absolute; top: 3px; left: 3px; z-index: 1; background: #2e2e2e; -o-transition: all 0.5s linear; -moz-transition: all 0.5s linear;#2E2E2E; -khtml-transition: all 0.5s linear; -webkit-transition: all 0.5s linear; -msmoz-transition: all 0.5s linear;  transition: all 0.5s linear; cursor: pointer; border-radius: 2px; -webkit-border-radius: 2px; -moz-border-radius: 2px; } .checkbox input[type=checkbox]:checked + label { left: 43px; } 

The html!HTML


<div class="checkbox"> <input type="checkbox" value="None"value="1" id="checkbox"id="checkbox1" name="check"/> <label for="checkbox"><for="checkbox1"></label> </div> 

And a FIDDLE for the above code note. Note that some cssCSS doesn't work in older versions of browsers, Butbut I'm sure there are some jqueryfancy JavaScript examples out there!

You can style checkboxs with lable example below:


The css!


input[type=checkbox] { visibility: hidden; } .checkbox { width: 80px; height: 26px; margin: auto; position: relative; background: #fff; border: 1px solid #2e2e2e; border-radius: 2px; -webkit-border-radius: 2px; -moz-border-radius: 2px; } .checkbox:after { content: 'No'; font: 12px/26px Arial, sans-serif; color: #b50000; position: absolute; right: 10px; z-index: 0; font-weight: bold; } .checkbox:before { content: 'Yes'; font: 12px/26px Arial, sans-serif; color: #00bf00; position: absolute; left: 10px; z-index: 0; font-weight: bold; } .checkbox label { display: block; width: 34px; height: 20px; position: absolute; top: 3px; left: 3px; z-index: 1; background: #2e2e2e; -o-transition: all 0.5s linear; -moz-transition: all 0.5s linear; -khtml-transition: all 0.5s linear; -webkit-transition: all 0.5s linear; -ms-transition: all 0.5s linear;  transition: all 0.5s linear; cursor: pointer; border-radius: 2px; -webkit-border-radius: 2px; -moz-border-radius: 2px; } .checkbox input[type=checkbox]:checked + label { left: 43px; } 

The html!


<div class="checkbox"> <input type="checkbox" value="None" id="checkbox" name="check"/> <label for="checkbox"></label> </div> 

And a FIDDLE for the above code note that some css doesn't work in older versions of browsers, But I'm sure there are some jquery examples out there!

You can style checkboxs with the label element an example is below:


The CSS


.checkbox input[type=checkbox] { visibility: hidden; } .checkbox { width: 80px; height: 26px; margin: auto; position: relative; background: #FFF; border: 1px solid #2E2E2E; border-radius: 2px; -webkit-border-radius: 2px; -moz-border-radius: 2px; } .checkbox:after { content: 'No'; font: 12px/26px Arial, sans-serif; color: #B50000; position: absolute; right: 10px; z-index: 0; font-weight: bold; } .checkbox:before { content: 'Yes'; font: 12px/26px Arial, sans-serif; color: #00BF00; position: absolute; left: 10px; z-index: 0; font-weight: bold; } .checkbox label { display: block; width: 34px; height: 20px; position: absolute; top: 3px; left: 3px; z-index: 1; background: #2E2E2E; transition: all 0.5s linear; -webkit-transition: all 0.5s linear; -moz-transition: all 0.5s linear; cursor: pointer; border-radius: 2px; -webkit-border-radius: 2px; -moz-border-radius: 2px; } .checkbox input[type=checkbox]:checked + label { left: 43px; } 

The HTML


<div class="checkbox"> <input type="checkbox" value="1" id="checkbox1" name="check"/> <label for="checkbox1"></label> </div> 

And a FIDDLE for the above code. Note that some CSS doesn't work in older versions of browsers, but I'm sure there are some fancy JavaScript examples out there!

Source Link
TURTLE
  • 3.9k
  • 4
  • 54
  • 55
Loading