html - 单选按钮样式不适用于 Firefox

标签 html css firefox

我找到了一篇 SO 文章,演示了如何将单选按钮更改为可点击按钮 here ,这在 Chrome 和 Safari 中很有效。但是,Firefox 无法正确呈现 CSS。文章提到该解决方案在 IE 中不起作用,只是不确定这是否意味着它在 Firefox 中也不起作用。

https://jsfiddle.net/eqyms7vc/2/

HTML

  <div id="service_type">
    <input type="radio" name="service_type" id="service_type_1" value="Option 1">
    <input type="radio" name="service_type" id="service_type_2" value="Option 2"> 
  </div>

CSS

#service_type .container {
    margin: 10px;
}

#service_type label {
    padding: 6px 12px;
    color: #fff;
}

#service_type input {
    -webkit-appearance:none;
    height:50px;
    width:150px;
    padding:10px;
    color:white;
    margin:5px;
    font-size: 18px;
    text-align: center;

}

#service_type input:hover {
  font-weight: bold;
}

#service_type input#service_type_1 {
  background:#336600;

}

#service_type input#service_type_2 {
  background:#0066ff;
}


#service_type input#service_type_1:before, input#service_type_1::before {
   content:"Option 1";
}

#service_type input:before, input::before {
    line-height:30px;
    width:100%;
    text-align:center;    
}

#service_type input#service_type_2:before, input#service_type_2::before {
   content:"Option 2";
}

#service_type .selected {
    background-color: #000;
}

如果没有办法让 Firefox 正确呈现上述 CSS,是否可以只向 Firefox 浏览器显示单选按钮标签?

谢谢!

最佳答案

您可以只隐藏单选按钮,并使用 label:before 伪元素来设置替代单选按钮的样式。此示例仅为 css,但如果需要,您也可以使用背景图片。

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

input[type=radio] + label:before{
  content: '•';
  display:inline-block;
  border-radius: 10px;
  width: 16px;
  height:16px;
  background:#8cf;
  color:#8cf;
  border: 2px solid #f00;
  line-height: 15px;
  text-align: center;
  font-size:25px;
  margin-right: 5px;
}

input[type=radio]:checked + label:before{
  color: #fff;
}
<input type="radio" name="group" id="radio1" /><label for="radio1">radiobutton</label><br />
<input type="radio" name="group" id="radio2" /><label for="radio2">radiobutton</label><br />
<input type="radio" name="group" id="radio3" /><label for="radio3">radiobutton</label><br />
<input type="radio" name="group" id="radio4" /><label for="radio4">radiobutton</label>

关于html - 单选按钮样式不适用于 Firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35188519/

相关文章:

html - 用于对齐文本框和标签的 CSS

css - 是否可以在 SASS 中创建循环以生成关键帧的供应商前缀

html - 我必须在页面的顶部中心对齐图像。我已经尝试了几乎所有我知道的可能的事情

firefox - YUI uploader + SSL + Firefox

Firefox 8 隐私浏览中的 Javascript 加速?

python - django v1.10 mysite.com 的 urls.py 条目 :8000/index. html

html - 盒子阴影 : inset on img tag

css - 如何将 xul 元素倾斜到可变大小的居中元素的右侧?

javascript - 如果输入未聚焦则隐藏 div

css - 你如何显示:table-cell width:100% - 270px