1.css 用::before和::after
html:
<input class='radio_type' type='radio' name='type' id='choose' checked='checked'/>
<label for='choose'></label>
//如果另外有文字标签,可以用label包住input和文字标签
css:
- 文字对齐:vertical-align: middle;
.radio_type {
width: 20px;
height: 20px;
appearance: none;
position: relative;
}
.radio_type:before {
content: '';
width: 20px;
height: 20px;
border: 1px solid #7d7d7d;
display: inline-block;
border-radius: 50%;
vertical-align: middle;
}
.radio_type:checked:before {
content: '';
width: 20px;
height: 20px;
border: 1px solid #2CC17B;
background: #2CC17B;
display: inline-block;
border-radius: 50%;
vertical-align: middle;
}
/*选中之后小勾*/
.radio_type:checked:after {
content: '';
width: 10px;
height: 5px;
border: 2px solid white;
border-top: transparent;
border-right: transparent;
text-align: center;
display: block;
position: absolute;
top: 6px;
left: 5px;
vertical-align: middle;
transform: rotate(-45deg);
}
.radio_type:checked + label {
color: #c59c5a;
}
方法二:
用background的方式;
background-position 属性设置背景图像的起始位置。
<label class="ck-mr">
<div class="icheckbox_minimal checked">
<input type="checkbox" value="" name="xdname" class="input_"/></div>
<span class="xdname">选项一</span></label>
css:
.icheckbox_minimal{
display: inline-block;
vertical-align: middle; //上下居中对齐
margin: 0;
padding: 0;
width: 19px;
height: 19px;
background: url(minimal.png) no-repeat; //重点:背景图
background-position: 0 0;//重点:图片显示的位置
border: none;
cursor: pointer;
position: relative;//定位
}
//隐藏原本的input
.input_{
position: absolute;
opacity: 0;
}
//点击之后
.icheckbox_minimal.checked {
background-position: -40px 0; //图片显示位置
背景图是这个:
点击前后:
用background-position调整位置就行了