Skip to content

Instantly share code, notes, and snippets.

@jhthorsen
Created December 11, 2017 07:54
Show Gist options
  • Select an option

  • Save jhthorsen/13f7f7689e98f26ed80c921b22b77302 to your computer and use it in GitHub Desktop.

Select an option

Save jhthorsen/13f7f7689e98f26ed80c921b22b77302 to your computer and use it in GitHub Desktop.
Css for styling checkboxes with css
label.checkbox,
label.radio {
cursor: pointer;
position: relative;
}
label.checkbox input + span,
label.radio input + span {
margin-left: 1.6rem;
}
label.checkbox input + span:before,
label.radio input + span:before {
content: "\00a0";
background-color: #fefefe;
color: #242424;
font-size: 1rem;
text-align: center;
vertical-align: top;
margin-right: 4px;
border: 1px solid #cacaca;
width: 1.3rem;
height: 1.3rem;
line-height: 1.3rem;
display: inline-block;
position: absolute;
top: 3px;
left: 0;
}
label.checkbox:hover input + span:before,
label.radio:hover input + span:before {
border-color: #0a0a0a;
}
label.checkbox input[disabled] + span,
label.radio input[disabled] + span {
color: #707070;
cursor: not-allowed;
}
label.checkbox:hover input[disabled] + span:before,
label.radio:hover input[disabled] + span:before {
border: 1px solid #cacaca;
}
label.checkbox input:checked + span:before,
label.radio input:checked + span:before {
content: "\2713";
background-color: #666;
border-color: #666;
color: #e5e5e5;
}
label.checkbox input,
label.radio input {
position: absolute;
left: -9999px;
opacity: 0;
}
label.checkbox input:focus + span:before,
label.radio input:focus + span:before {
outline: 5px auto #99999e;
outline-offset: -2px;
}
label.checkbox input + span:before {
border-radius: 2px;
}
label.radio input + span:before {
border-radius: 0.83333rem;
line-height: 1.1rem;
}
label.radio input:checked + span:before {
content: "\25CF";
padding-top: 1px;
background-color: #fefefe;
color: #666;
}
<label class="checkbox">
<input type="checkbox" name="foo">
<span class="label">Click me!</span>
</label>
<label class="radio">
<input type="radio" name="bar">
<span class="label">Click me!</span>
</label>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment