复选框设置背景

更改复选框的默认样式

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<!doctype html>
<html>

<head>
<meta charset="utf-8">
<title>chec</title>

<style>
#container {
margin: 20px auto;
}

#container span {
position: relative;
}

#container .input_check {
position: absolute;
visibility: hidden;
}

#container .input_check+label {
display: inline-block;
width: 16px;
height: 16px;
border: 1px solid #fd8845;
}
#container .input_check:checked+label{
background-color: green;
}
#container .input_check:checked+label:after {
content: "";
position: absolute;
left: 2px;
bottom: 12px;
width: 9px;
height: 4px;
border: 2px solid #fd8845;
border-top-color: transparent;
border-right-color: transparent;
-ms-transform: rotate(-60deg);
-moz-transform: rotate(-60deg);
-webkit-transform: rotate(-60deg);
transform: rotate(-45deg);

}
</style>
</head>

<body>

<h3>利用css的:after跟transform属性代替checkbox效果</h3>
<div id="container">
<span><input type="checkbox"class="input_check" id="check3"><label for="check3"></label></span>
<span><input type="checkbox"class="input_check" id="check4"><label for="check4"></label></span>
</div>
</body>

</html>

当前网速较慢或者你使用的浏览器不支持博客特定功能,请尝试刷新或换用Chrome、Firefox等现代浏览器