先把原来的复选框隐藏掉,再把lable伪装成复选框
设置 lable 的样式和 lable 选中时候的样式。
::before和::after必须配合content属性来使用,content用来定义插入的内容,content必须有值,至少是空。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
#checkboxFourInput{
visibility: hidden;
}
#checkboxFourInput+label{
background-color: white;
border-radius: 50px;
border: 2px solid #b55959;
width: 20px;
height: 20px;
display: inline-block;
text-align: center;
vertical-align: middle;
line-height: 20px;
}
#checkboxFourInput:checked + label{
background-color: #fff;
}
/* #checkboxFourInput:checked + label:after{
content: "";
border-radius: 50px;
left: 34.5px;
position: absolute;
background: #b55959;
border: #fff solid 2px;
height: 16px;
width: 16px;
} */
#checkboxFourInput:checked + label:after{
content: "\2713";
}
</style>
</head>
<body>
<div class="choosePwd">
<input type="checkbox" id="checkboxFourInput"/>
<label for="checkboxFourInput"></label>
</div>
</body>
</html>
效果: