Skip to content

Instantly share code, notes, and snippets.

@itwasmattgregg
Last active May 5, 2016 16:23
Show Gist options
  • Save itwasmattgregg/7eac8a46ceb90313d576729f5ca01880 to your computer and use it in GitHub Desktop.
Save itwasmattgregg/7eac8a46ceb90313d576729f5ca01880 to your computer and use it in GitHub Desktop.
Checkbox with one pseudo element with only css
<div class="checkbox">
<label>
<input type="checkbox"> Checkbox
</label>
</div>
.checkbox {
position: relative;
padding-top: 7px;
label {
padding-left: 20px;
cursor: pointer;
}
input[type="checkbox"] {
position: absolute;
display: inline-block;
-webkit-appearance: none;
margin: 0;
cursor: pointer;
left: 0;
bottom: 3px;
border-radius: 2px;
outline: none;
width: 14px;
height: 14px;
border: 1px solid #ddd;
background: white;
&:after {
box-sizing: border-box;
position: absolute;
bottom: 1px;
left: 3px;
content: " ";
width: 5px;
height: 10px;
border: solid transparent;
border-width: 0 2px 2px 0;
transform: rotate(45deg) translate(0px, -1px);
}
&:checked {
&:after {
border-color: green;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment