Skip to content

Instantly share code, notes, and snippets.

@netzulo
Created October 11, 2016 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netzulo/7ee596a84c41d1c60553e227425f52db to your computer and use it in GitHub Desktop.
Save netzulo/7ee596a84c41d1c60553e227425f52db to your computer and use it in GitHub Desktop.
Styling HTML Checkboxes
<div>
<input type="checkbox" name="checkbox-option" id="chk-opt-1" class="hide-checkbox" value="opt1" checked>
<label for="chk-opt-1">.com</label>
<input type="checkbox" name="checkbox-option" id="chk-opt-2" class="hide-checkbox" value="opt1" checked>
<label for="chk-opt-2">.org</label>
<input type="checkbox" name="checkbox-option" id="chk-opt-3" class="hide-checkbox" value="opt3" checked>
<label for="chk-opt-3">.net</label>
<input type="checkbox" name="checkbox-option" id="chk-opt-4" class="hide-checkbox" value="opt4" checked>
<label for="chk-opt-4">.es</label>
</div>
<div>
<input type="checkbox" name="checkbox-option" id="chk-opt-5" class="hide-checkbox" value="opt5" checked>
<label for="chk-opt-5">.me</label>
<input type="checkbox" name="checkbox-option" id="chk-opt-6" class="hide-checkbox" value="opt6" checked>
<label for="chk-opt-6">.biz</label>
<input type="checkbox" name="checkbox-option" id="chk-opt-7" class="hide-checkbox" value="opt7" checked>
<label for="chk-opt-7">.co</label>
<input type="checkbox" name="checkbox-option" id="chk-opt-8" class="hide-checkbox" value="opt8" checked>
<label for="chk-opt-8">.cc</label>
</div>
[].forEach.call( document.querySelectorAll('.hide-checkbox'), function(element) {
element.style.display = 'none';
});
.hide-checkbox + label {
display: inline-block;
width: 150px;
padding: 0.3rem 0;
text-align: center;
background-color: #e74c3c;
font-family: 'Oswald', sans-serif;
color: #fff;
-webkit-transition: background-color 0.3s ease-in-out;
-moz-transition: background-color 0.3s ease-in-out;
-o-transition: background-color 0.3s ease-in-out;
transition: background-color 0.3s ease-in-out;
}
.hide-checkbox:checked + label {
display: inline-block;
background-color: #2ecc71;
}
<link href="http://fonts.googleapis.com/css?family=Oswald" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment