 |
CSSでオリジナルのチェックボックスを作成する |
 |
CSSでオリジナルのチェックボックスを作成する
CSSで作成したオリジナルのチェックボックス例
htmlとcss
<div class="fontsize20pt">
<label>
<input type="checkbox" class="mam-chkbox" value="1" data-native="true">
<span class="mam-chkbox-rect">選択肢1(正方形)</span>
</label>
</div>
<div class="fontsize20pt">
<label>
<input type="checkbox" class="mam-chkbox" value="1" data-native="true">
<span class="mam-chkbox-rect mam-chkbox-roundrect">選択肢2(角が丸い正方形)</span>
</label>
</div>
<div class="fontsize20pt">
<label>
<input type="checkbox" class="mam-chkbox" value="1" data-native="true">
<span class="mam-chkbox-rect mam-chkbox-circle">選択肢3(円形)</span>
</label>
</div>
<style>
.fontsize20pt{font-size:20pt;}
.mam-chkbox {
display: none;
}
.mam-chkbox + .mam-chkbox-rect{
padding-left: 1.2em;
position: relative;
}
.mam-chkbox + .mam-chkbox-rect::before{
content: "";
display: block;
position: absolute;
top: 0;
left: 0;
width: 1em;
height: 1em;
padding:0;
margin: 0;
border: 1px solid #111;
background: #eee;
border-radius: 0;
}
/* checked属性有の要素の 直後の隣接要素 */
.mam-chkbox:checked + .mam-chkbox-rect::before {
background: #666;
}
/* checked属性有の要素の 直後の隣接要素 */
.mam-chkbox:checked + .mam-chkbox-rect::after {
content: "";
display: block;
position: absolute;
top: 0.7em;
left: 0.2em;
width: 0.5em;
height: 0.3em;
margin-top:-0.5em; /* ネガティブマージン */
transform: rotate(-45deg); /* 反時計回り 45度 */
border-top:none;
border-bottom: 0.2em solid #eee;
border-left: 0.2em solid #eee;
border-right:none;
}
.mam-chkbox + .mam-chkbox-roundrect::before{
border-radius:30%;
}
.mam-chkbox + .mam-chkbox-circle::before{
border-radius:50%;
}
</style>
Mam's WebSite