Created
May 29, 2019 00:32
-
-
Save tsmd/833ec6ed917eedc63ba3aaa1caeb52bb to your computer and use it in GitHub Desktop.
Cool radio button
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
@charset "UTF-8"; | |
.Radio { | |
@at-root { | |
& { | |
position: relative; | |
z-index: 0; | |
display: inline-flex; | |
justify-content: flex-start; | |
align-items: baseline; | |
line-height: 1.8; | |
} | |
.Radio__input { | |
position: absolute; | |
z-index: -1; | |
opacity: 0; | |
} | |
.Radio__icon { | |
flex: 0 0 auto; | |
position: relative; | |
top: 0.1em; // vertical-align としての役割 | |
width: 1em; | |
height: 1em; | |
border-radius: 51%; | |
background-color: $color-gray30; | |
// クリック範囲拡張 | |
&::before { | |
content: ''; | |
position: absolute; | |
top: -50%; | |
left: -50%; | |
width: 200%; | |
height: 200%; | |
} | |
&::after { | |
content: ''; | |
position: absolute; | |
top: 0; | |
right: 0; | |
bottom: 0; | |
left: 0; | |
margin: auto; | |
display: none; | |
width: (6px / 16px) * 100%; | |
height: (6px / 16px) * 100%; | |
border-radius: 51%; | |
background-color: #fff; | |
} | |
} | |
.Radio__label { | |
margin-left: (6px / 16px) * 1em; | |
} | |
// フォーカス | |
:focus.focus-visible ~ .Radio__icon { | |
box-shadow: 0 0 0 4px rgba($color-primary, 0.5); | |
} | |
// チェック済み | |
:checked ~ .Radio__icon { | |
background-color: $color-primary; | |
&::after { | |
display: block; | |
} | |
} | |
// 使用不可 | |
:disabled { | |
& ~ .Radio__icon { | |
background-color: $color-gray10; | |
&::after { | |
background-color: $color-gray30; | |
} | |
} | |
& ~ .Radio__label { | |
color: $color-gray60; | |
} | |
} | |
} | |
} |
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="ja"> | |
<title>Radio</title> | |
<label class="Radio"> | |
<input class="Radio__input" type="radio" name="radio" aria-label="テキストラベル"> | |
<span class="Radio__icon"></span> | |
</label> | |
<label class="Radio"> | |
<input class="Radio__input" type="radio" name="radio"> | |
<span class="Radio__icon"></span> | |
<span class="Radio__label"> | |
テキストラベル | |
</span> | |
</label> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment