繁体   English   中英

使用CSS3自定义复选框和单选按钮

[英]customizing checkboxes and radio buttons using CSS3

这里我有各自样式的复选框和单选按钮

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>

我想改变图像:悬停 ,我该怎么做

工作演示

使用此代码:

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');

这是为了在悬停时停止图标从绿色变为灰色。

这是工作: http//jsfiddle.net/tT6tD/1/

试试这个

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;}

http://jsfiddle.net/P8Qrq/4/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM