这里我有各自样式的复选框和单选按钮
HTML
<h3>Radio buttons</h3>
<div class="radio">
<input id="radio-1" type="radio" name="Data1" value="agree" checked />
<label for="radio-1">Yes</label>
<input id="radio-2" type="radio" name="Data1" value="disagree" />
<label for="radio-2">No</label>
</div>
<h3>Checkboxes</h3>
<div class="checkbox">
<input id="checkbox-1" type="checkbox" name="Data2" value="option1" checked />
<label for="checkbox-1">HTML</label>
<br />
<input id="checkbox-2" type="checkbox" name="Data3" value="option2" />
<label for="checkbox-2">CSS</label>
</div>
我想更改:悬停上的图片,我该怎么做
答案 0 :(得分:4)
使用此代码:
input[type=checkbox] + label:hover:before, input[type=radio] + label:hover:before{
background: url('http://cnt.in.bookmyshow.com/bmsin/SLIMG/1_2.gif?v1');
}
结合两个css伪类 - :hover:before
来实现效果。
我还更改了“选定的”背景代码:
background: url('http://cnt.in.bookmyshow.com/bmsin/SLIMG/1_4.gif') !important;
到
background: url('http://cnt.in.bookmyshow.com/bmsin/SLIMG/1_4.gif');
这是为了在悬停时停止图标从绿色变为灰色。
答案 1 :(得分:0)
试试这个
input[type="checkbox"], input[type="radio"] {display: none;}
input[type="checkbox"] + label, input[type="radio"] + label {padding-left: 20px;}
input[type="checkbox"] + label {background: url('http://i.imgur.com/LpSXDFI.png') no-repeat 0 center;}
input[type="radio"] + label {background: url('http://i.imgur.com/YWUFP1H.png') no-repeat 0 center;}
input[type="checkbox"]:checked + label {background: url('http://i.imgur.com/xS4jaLI.png') no-repeat 0 center;}
input[type="checkbox"]:checked + label, input[type="checkbox"]:hover + label {background: url('http://i.imgur.com/xS4jaLI.png') no-repeat 0 center;}
input[type="radio"]:checked + label, input[type="radio"]:hover + label {background: url('http://i.imgur.com/q4VadN4.png') no-repeat 0 center;}