我正在尝试使用纯 CSS 制作自定义复选框,没有必需的标签元素,我知道有很多答案,但我没能按需要制作它。 唯一的问题是当复选框被选中时,我不知道如何添加选中的符号,这是我现在所拥有的
.checkbox-custom {
&:after {
line-height: 1.5em;
content: '';
display: inline-block;
width: 18px;
height: 18px;
margin-top: -4px;
margin-left: -4px;
border: 1px solid grey;
border-radius: 0;
background-color: white;
}
&:checked:after {
width: 15px;
height: 15px;
color: grey;
}
}
<input type="checkbox" class="checkbox-custom">
最佳答案
如果您希望在之后添加复选标记,请将 content
与 html 实体(css 编码)一起使用
.checkbox-custom::after {
line-height: 1.5em;
content: '';
display: inline-block;
width: 18px;
height: 18px;
margin-top: -4px;
margin-left: -4px;
border: 1px solid grey;
border-radius: 0;
background-color: white;
}
.checkbox-custom:checked::after {
content:'\2713';
font-size: 20px;
line-height: 1em;
width: 18px;
height: 18px;
color: grey;
text-align:center;
}
<input type="checkbox" class="checkbox-custom">
关于css - 创建没有后元素的自定义复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53281304/