样式单选按钮似乎只适用于Chrome

时间:2015-12-17 18:50:08

标签: html css

Pure CSS适用于Chrome。但并非所有浏览器。

有什么想法吗?

这是我的示例代码:

https://jsfiddle.net/kdtrtb03/5/

<label class="radioLabel">
    <input type='radio' value='false' name='test' />
    <span>No&nbsp;</span>
</label>
<label class="radioLabel">
    <input type='radio' value='true' name='test' />
    <span>Yes&nbsp;</span>
</label>



.radioLabel {
        padding-left: 10px;
}
.radioLabel span {
        padding-left: 17px;
        padding-top: 5px;
}

.radioLabel input[type=radio] {
        cursor:pointer !important; 
}

.radioLabel input[type=radio]:after {
        content:' ';
        position:relative;
        display:inline-block;
        top:-2px;
        left:-2px;
        width:15px;
        height:15px;
        background-color:gray;
        border-radius:20px;
        border:gray solid 4px;
}

.radioLabel input[type=radio]:checked:after {
        background-color:red;
}

1 个答案:

答案 0 :(得分:4)

输入不能包含:after:before元素,您应该将css应用于范围:

.radioLabel span:before {
  content: ' ';
  position: relative;
  display: inline-block;
  top: -2px;
  left: -2px;
  width: 15px;
  height: 15px;
  background-color: gray;
  border-radius: 20px;
  border: gray solid 4px;
}

.radioLabel input[type="radio"]:checked + span:before {
  background-color: red;
}

JSFiddle Demo