Nil*_*ubi 1 html javascript css jquery web
我有一个非常简单的问题,但我找不到一个简单的答案。
我有一个如下所示的复选框:
<input type="checkbox">
Run Code Online (Sandbox Code Playgroud)
我想在选中此复选框时仅更改背景颜色。
有没有一种简单的方法可以在 CSS 或 JS 中做到这一点?
您可以简单地使用:checked伪类和:after伪元素在选中时为背景着色。
编辑:为了获得复选框的完整背景,我们需要完全自定义该复选框。它是一个完整的 CSS 解决方案。
input[type="checkbox"]:checked {
background: blue;
color: white;
}
input[type="checkbox"] {
cursor: pointer;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
outline: 0;
background: lightgray;
height: 16px;
width: 16px;
border: 1px solid white;
color: white;
}
input[type="checkbox"]:after {
content: ' ';
position: relative;
left: 40%;
top: 20%;
width: 15%;
height: 40%;
border: solid #fff;
border-width: 0 2px 2px 0;
transform: rotate(50deg);
display: none;
}
input[type="checkbox"]:checked:after {
display: block;
}
Run Code Online (Sandbox Code Playgroud)
<input type="checkbox" />
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
12080 次 |
最近记录: |