Html 使用CSS3自定义复选框和单选按钮
在这里,我有复选框和单选按钮各自的风格 HTMLHtml 使用CSS3自定义复选框和单选按钮,html,css,Html,Css,在这里,我有复选框和单选按钮各自的风格 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"
<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>
单选按钮
对
不
复选框
HTML
CSS
我想更改上的图像:悬停,如何更改
使用以下代码:
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');
}
Is组合了两个css伪类-:hover:before
以实现效果
我还将您的“选定”背景代码更改为:
background: url('http://cnt.in.bookmyshow.com/bmsin/SLIMG/1_4.gif') !important;
到
这是为了防止悬停时图标从绿色变为灰色
它开始工作了:试试这个
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;}
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;}