2013-03-08 134 views
0

我跟随wittysparks.com创建自定义单选按钮的任何工作都很好,但如果在标签中添加更多内容将显示未使用的图像。CSS3自定义单选按钮问题

下面的代码正在工作中查找。

<input id="radio2" name="groupradio" type="radio" value="Radio 2" tabindex="6" /><label  for="radio2">I am Group Radio 2 </br> 
</label> 

在代码中添加更多内容后会出现问题。

<input id="radio2" name="groupradio" type="radio" value="Radio 2" tabindex="6" /><label for="radio2">I am Group Radio 2 </br> 
I am Group Radio 2 </br> 
I am Group Radio 2 </br> 
I am Group Radio 2 </br> 
I am Group Radio 2 </br> 
I am Group Radio 2 </br> 
I am Group Radio 2 </br> 
I am Group Radio 2 </br> 
I am Group Radio 2 </br> 
</label> 

这是我的CSS

/*! 
* WittySparks - (c) Sravan Kumar, freely distributable, can modify as per your needs. 
* WittySparks.com.com 
*/ 
input[type='radio'], input[type='checkbox']{opacity:0;position:absolute;filter:alpha(opacity=0);margin:5px 0 0 5px} 
input[type='radio']:focus+label, input[type="checkbox"]:focus+label{color:#C30} 
input[type="checkbox"]+label, input[type="radio"]+label{background:url('wittysparks_checkbox_radio.png') left top no-repeat;position:relative;margin:0;padding:0 0 0 50px;cursor:pointer;line-height:43px;min-height:43px;display:inline-block;z-index:0;font-size:30px;font-weight:bold} 
input[type="checkbox"]+label{background-position:0 0} 
input[type="radio"]+label{background-position:0 -200px} 
input[type='checkbox']:checked+label{background-position:0 -100px} 
input[type='radio']:checked+label{background-position:0 -300px} 
input[type='checkbox']:disabled+label{background-position:0 -400px;color:#999} 
input[type='radio']:disabled+label{background-position:0 -600px;color:#999} 
input[type='checkbox']:disabled:checked+label{background-position:0 -500px;color:#999} 
input[type='radio']:disabled:checked+label{background-position:0 -700px;color:#999} 

教程web站点。 “http://www.wittysparks.com/2012/04/17/pure-css3-custom-checkbox-and-radio-buttons-with-sprite-image/

更新的jsfiddle

http://jsfiddle.net/shivanraptor/fdEHj/1/

+1

发布您的CSS以及。 – Raptor 2013-03-08 02:15:38

+0

hello Shivan Raptor我已经发布了我的css upside.thank you – sum7 2013-03-08 02:23:38

回答

0

的CSS本身是标签的高度影响。如果标签的高度降低到1或2线,问题就会消失。

尝试通过CSS分离标签的效果。

+0

hi Shivan Raptor我已经使用“selectivizr-min.js”来破解IE浏览器。和“:focus”函数在ie7和ie8 .thx – sum7 2013-03-08 02:30:34

+0

中工作正常,如果您有任何额外的框架/ JS使用,请提及它。另外,你使用的JS不支持':focus + label'。如果您打算支持旧版浏览器,则不应冒风险使用新技术。交换图像的'onclick'已经足够您的案例。 – Raptor 2013-03-08 02:36:02

+0

thx u回复Shivan猛禽,不仅在ie7中现在所有的浏览器也是同样的问题。 – sum7 2013-03-08 02:52:16

0

,让我的单选按钮,而不是默认的一次,根据浏览器的变化,我用这个:http://www.screwdefaultbuttons.com/

它工作在IE6 +,Chrome浏览器,火狐,Safari ......

http://www.screwdefaultbuttons.com/

包括标题脚本:

<script src="js/jquery.screwdefaultbuttonsV2.min.js" ></script> 

CSS

$('input:radio').screwDefaultButtons({ 
    image: "url(images/radio.jpg)", 
    width: 85, 
    height: 85 
}); 

.styledRadio { 
/* Your styles here */ 
} 

.styledCheckbox { 
    /* Your styles here */ 

} 
+0

尽管这个链接可能回答这个问题,但最好在这里包含答案的重要部分,并提供供参考的链接。如果链接页面更改,则仅链接答案可能会失效。 – 2015-03-13 12:06:15

+0

你是对的..编辑:) – md27 2015-03-13 12:21:02