2013-04-05 112 views
0

我想勾选复选框。我能够使用以下HTML标记和CSS来完成此操作。造型单选按钮

但问题是我有一点不同的HTML标记,我不能改变。 无法更改的原因是它是由插件生成的,所以我需要编辑核心文件来改变这一点,我不想这样做。

那么如何添加相同的样式到我下面的HTML中。

工作HTML:

<input type="radio" id="radio"> 
<label for="radio"></label> 

所需的HTML:

<li> 
    <input id="option-11" type="radio" value="11"> 
    <label for="option-11">Option one</label> 
</li> 

正如你可以看到,虽然标记是相似的,但在标签上面用来显示文本。

CSS:

input[type="radio"], input[type="checkbox"] { 
    display: none; 
} 

input[type="radio"] + label{ 
    background:url('http://refundfx.com.au/uploads/image/checkbox_empty.png'); 
    padding:0; 
    display: inline-block; 
    width:20px; 
    height:20px; 
} 

input[type="radio"]:checked + label { 
    background:url('http://refundfx.com.au/uploads/image/checkbox_full.png'); 
} 

演示: http://jsfiddle.net/JPSLm/

+0

究竟是什么问题呢?有点不清楚。 – 2013-04-05 07:54:41

+0

你可以看到,CSS隐藏实际的无线电输入,并使用标签来设计无线电盒,我有不同的HTML,我不能改变(如你所见),我怎样才能添加样式到该HTML获得相同的样式无线电输入。 – user1251698 2013-04-05 07:59:08

+0

我不知道问题出在哪里...... http://jsfiddle.net/tvVQT/ – mnme 2013-04-05 08:01:49

回答

-1

它与你的代码,我不知道问题出在哪里。

http://jsfiddle.net/sGqsL/

HTML

<li> 
    <input type="radio" id="radio" name="radiogroup"/> 
    <label for="radio"></label> 
</li> 

和CSS

input[type="radio"], input[type="checkbox"] { 
    display: none; 
} 

input[type="radio"] + label{ 
    background:url('http://refundfx.com.au/uploads/image/checkbox_empty.png'); 
    padding:0; 
    display: inline-block; 
    width:20px; 
    height:20px; 
} 

input[type="radio"]:checked + label { 
    background:url('http://refundfx.com.au/uploads/image/checkbox_full.png'); 
} 

li { 
    list-style-type: none; 
} 
+1

为什么你添加了作为答案,如果它与原始代码一起工作? – Morpheus 2013-04-05 08:50:46