css 自定义复选框输入|标签的CSS
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了css 自定义复选框输入|标签的CSS相关的知识,希望对你有一定的参考价值。
<ul class="unstyled centered">
<li>
<div class="checkbox">
<input class="custom-checkbox" id="cbid1" type="checkbox" value="value1">
<label for="cbid1">Checkbox</label>
</div>
</li>
<li>
<div class="checkbox">
<input class="custom-checkbox" id="cbid2" type="checkbox" value="value2" checked>
<label for="cbid2">CSS Only</label>
</div>
</li>
<li>
<div class="checkbox">
<input class="custom-checkbox" id="cbid3" type="checkbox" value="value3" disabled>
<label for="cbid3">A disabled checkbox</label>
</div>
</li>
<li>
<div class="checkbox">
<input class="custom-checkbox" id="cbid4" type="checkbox" value="value4">
<label for="cbid4">Fourth option</label>
</div>
</li>
</ul>
.custom-checkbox {
position: absolute; // take it out of document flow
opacity: 0; // hide it
& + label {
position: relative;
cursor: pointer;
padding: 0;
}
// Box.
& + label:before {
content: '';
margin-right: 10px;
display: inline-block;
vertical-align: text-top;
width: 20px;
height: 20px;
background: white;
border: 1px solid #000;
}
// Box hover
&:hover + label:before {
background: #5591dc;
}
// Box focus
&:focus + label:before {
//box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.12);
}
// Box checked
&:checked + label:before {
background: #5591dc;
}
// Disabled state label.
&:disabled + label {
color: #b8b8b8;
cursor: auto;
}
// Disabled box.
&:disabled + label:before {
box-shadow: none;
background: #ddd;
}
// Checkmark. Could be replaced with an image
&:checked + label:after {
content: '';
position: absolute;
left: 5px;
top: 9px;
background: white;
width: 2px;
height: 2px;
box-shadow:
2px 0 0 white,
4px 0 0 white,
4px -2px 0 white,
4px -4px 0 white,
4px -6px 0 white,
4px -8px 0 white;
transform: rotate(45deg);
}
}
以上是关于css 自定义复选框输入|标签的CSS的主要内容,如果未能解决你的问题,请参考以下文章
选中时尝试更改自定义复选框标签的颜色,仅 CSS [重复]
css 自定义文件输入|标签的CSS
css 自定义无线电输入|标签的CSS
前端html+css零基础入门教程
css 自定义复选框CSS
css 自定义复选框图像