Created
August 22, 2022 22:53
-
-
Save stuarthallows/c92a2b10612b238cf19c6a3ce67c87e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | |
<title>Custom Checkbox</title> | |
<style> | |
*, | |
*::before, | |
*::after { | |
box-sizing: border-box; | |
} | |
.custom-checkbox + label { | |
display: flex; | |
align-items: center; | |
cursor: pointer; | |
} | |
.custom-checkbox { | |
position: absolute; | |
left: -9999px; | |
opacity: 0; | |
} | |
.custom-checkbox + label::before { | |
content: ""; | |
width: 1.1em; | |
height: 1.1em; | |
margin-right: 0.5em; | |
border-radius: 0.15em; | |
border: 0.05em solid black; | |
} | |
.custom-checkbox + label:hover::before { | |
background-color: #0af; | |
} | |
.custom-checkbox:focus + label::before { | |
box-shadow: 0 0 20px 0 black; | |
} | |
.custom-checkbox:checked + label::before { | |
content: "✔"; | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
background-color: #069; | |
color: white; | |
} | |
.custom-checkbox:disabled + label { | |
color: #aaa; | |
cursor: not-allowed; | |
} | |
.custom-checkbox:disabled + label::before { | |
background-color: #ccc; | |
border-color: #999; | |
} | |
</style> | |
</head> | |
<body> | |
<input class="custom-checkbox" type="checkbox" id="cb1" disabled checked /> | |
<label for="cb1">Checkbox 1</label> | |
<br /> | |
<input class="custom-checkbox" type="checkbox" id="cb2" disabled /> | |
<label for="cb2">Checkbox 2</label> | |
<br /> | |
<input class="custom-checkbox" type="checkbox" id="cb3" /> | |
<label for="cb3">Checkbox 3</label> | |
<br /> | |
<input class="custom-checkbox" type="checkbox" id="cb4" /> | |
<label for="cb4">Checkbox 4</label> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment