首先,先由
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.checkbox:checked + i {
color :red;
}
</style>
</head>
<body>
<label>
<input type="checkbox" class="checkbox">
<i>·</i>
</label>
</body>
</html>
可以引导出,当点击input标签时,点的颜色也会随之发生变化
从而开始去隐藏前面的input标签,达到自定义样式的作用,而隐藏input标签我们可以采用,display为none的方式或者是opcity=0加定位的方式
这是伪元素的做法
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.checkbox {
display: none;
/*opacity: 0*/
}
.checkbox + i::after {
content: '☆';
}
.checkbox:checked + i::after {
content: '★';
}
</style>
</head>
<body>
<label>
<input type="checkbox" class="checkbox">
<i></i>
</label>
</body>
</html>
再进一步的方法是
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.checkbox {
display: none;
/*opacity: 0*/
}
.checkbox + i {
display: inline-block;
border-radius: 50%;
content: ' ';
width: 20px;
height: 20px;
background-color: #eee;
}
.checkbox:checked + i {
background-color: skyblue;
}
.checkbox:checked + i::after {
content: ' ';
display: inline-block;
width: 10px;
height: 10px;
margin: 5px;
border-radius: 50%;
background-color: #eee;
}
</style>
</head>
<body>
<label>
<input type="checkbox" class="checkbox">
<i></i>
</label>
</body>
</html>
效果图


网友评论