首页 > Web开发 > 详细

纯css设置单选框/进度条样式

时间:2015-12-25 22:20:44      阅读:272      评论:0      收藏:0      [点我收藏+]

1.设置radio样式

注意:radio的id要和对应的label 的for相同。

原理:使用 :checked+label 切换样式图片。checkbox也可以这么做。

CSS:

            input[type=radio] {
            	float: left;
            	visibility: hidden;
            }	
            label {
            	float: left;
            	width: 16px;
            	height: 15px;
            	margin: 18px 5px 0 0;
            	background: url(../images/arrow.png) no-repeat;
            	cursor: pointer;
            }
            .l1 {
                background-position: -237px -184px;
                background-size: 250px;
            }
            .l2 {
            	background-position: -236px -156px;
            	background-size: 250px;
            }
            #r1:checked + label {
                
                background-position: -210px -184px;
            }
            #r2:checked + label {
            	background-position: -212px -156px;
            }

  

HTML:

                        <div class="male">
		    		<input type="radio" checked="checked" name="sexlist" id="r1" />
		    		<label for="r1" class="l1"></label>男
		    	</div>
		    	<div class="female">
		    		<input type="radio" name="sexlist" id="r2" />
		    		<label for="r2" class="l2"></label>女
		    	</div>

 

效果:

技术分享

技术分享

 

技术分享

技术分享

2.进度条样式(摘自http://lab.tianyizone.com/demo/form/form_demo_css.html)

原理:为三个页面的进度条分别设置不同的value,由此切换背景图片。

CSS:

progress {display: block;width: 300px;height: 35px;margin-bottom:10px;-webkit-appearance:none;}
progress::-webkit-progress-bar { background: url(bg_step.png) no-repeat 0 0; }
progress::-webkit-progress-value  { background: url(bg_step.png) no-repeat 0 -50px; }
progress[value="2"]::-webkit-progress-value  { background-position: 0 -100px; }
progress[value="3"]::-webkit-progress-value  { background-position: 0 -150px; }

 

HTML:

<progress max="3" value="2"></progress>

其中max定义完成值,value定义当前值。

效果:

技术分享

技术分享

技术分享

 

纯css设置单选框/进度条样式

原文:http://www.cnblogs.com/17shiooo/p/5077054.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!