Created
December 11, 2017 07:54
-
-
Save jhthorsen/13f7f7689e98f26ed80c921b22b77302 to your computer and use it in GitHub Desktop.
Css for styling checkboxes with css
This file contains hidden or 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
| 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; | |
| } |
This file contains hidden or 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
| <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