radio和checkbox的美化

2018-01-24

radio和checkbox的绘制

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<div class="form">
<div class="radio">
<label class="radio-wrap">
<input type="radio" name="sex" id="man" value="1" />
<span></span>
</label>
<label for="man">先生</label>
<label class="radio-wrap">
<input type="radio" name="sex" id="woman" value="0" />
<span></span>
</label>
<label for="woman">女士</label>
</div>
<div class="checkbox">
<label class="checkbox-wrap">
<input type="checkbox" id="agreement"/>
<span></span>
</label>
<label for="agreement">同意协议</label>
</div>
</div>
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
60
61
62
.form {
background: #cccccc;
color: #ffffff;
width: 800px;
margin: 10px auto 0;
padding: 10px;
}

.radio-wrap, .checkbox-wrap {
display: inline-block;
vertical-align: middle;
margin-left: 2rem;
margin-right: 0.5rem;
}
.radio-wrap:first-of-type, .checkbox-wrap:first-of-type {
margin-left: 0;
}
.radio-wrap input, .checkbox-wrap input {
display: none;
}
.radio-wrap span, .checkbox-wrap span {
cursor: pointer;
display: inline-block;
position: relative;
border: 1px solid #ffffff;
border-radius: 3px;
overflow: hidden;
padding: 1px;
}
.radio-wrap span:before, .checkbox-wrap span:before {
content: "";
display: block;
width: 11px;
height: 11px;
}
.radio-wrap input:checked ~ span, .checkbox-wrap input:checked ~ span {
border-color: red;
}

.radio span:before {
opacity: 0;
border-radius: 2px;
background-color: red;
}
.radio input:checked ~ span {
border-color: red;
}
.radio input:checked ~ span:before {
opacity: 1;
}

.checkbox-wrap input:checked ~ span {
border-color: red;
}
.checkbox-wrap input:checked ~ span:before {
content: "\2713";
color: red;
font-size: 12px;
font-weight: bold;
line-height: 1;
text-align: center;
}