【发布时间】:2014-11-27 23:44:31
【问题描述】:
我想用这种方式设置单选按钮的样式:
我现在的代码如下所示:
input[type=radio] {
display:none;
}
input[type=radio]:checked +label:before {
background:green;
width: 15px;
height: 15px;
border: 0;
border-radius: 50%;
}
label {
color:black;
font-family:arial;
font-size:12px;
position:relative;
padding-left:20px;
}
label:hover {
color:green;
}
label:hover:before {
border:1px solid green;
border-radius: 50%;
}
label:before {
content:'';
height:13px;
width:13px;
border:1px solid lightgray;
border-radius: 50%;
display:inline-block;
position:absolute;
top:0;
left:0;
}
和 HTML 代码:
<input id="kunstmuseum1" type="radio" name="kunstmuseum" onClick="animateKunst('voll')"> <label class="gruen" for="kunstmuseum1">Volle Subvention</label>
<input id="kunstmuseum2" type="radio" name="kunstmuseum" onClick="animateKunst('halb')"><label for="kunstmuseum2">Subventionen um die Hälfte kürzen</label>
<input id="kunstmuseum3" type="radio" name="kunstmuseum" checked="checked" onClick="animateKunst('null')"><label for="kunstmuseum3">Keine Subventionen mehr</label>
是否可以为 input[type=radio] 添加不同的类,如何将单选按钮仅填充一半?这是一个 jsfiddle:http://jsfiddle.net/x5d4tyq7/
【问题讨论】:
-
当单选按钮填满一半时,它仍然可以选择吗?
-
是的,它只是视觉效果,按钮之间也有差异,尽管我对视觉效果并不完全确定。我不知道如何分别为单选按钮设置不同的样式?例如:同一组单选按钮,但一个是绿色的,一个是橙色的,一个是红色的。
标签: javascript html css radio-button