我发现了一篇 SO 文章,演示了如何将单选按钮更改为可点击按钮,这在 Chrome 和 Safari 中非常有效。但是,Firefox 无法正确渲染 CSS。文章提到该解决方案在 IE 中不起作用,只是不确定这是否意味着它在 Firefox 中也不起作用。
https://jsfiddle.net/eqyms7vc/2/
超文本标记语言
<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>
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)
如果没有办法让 Firefox 正确渲染上述 CSS,是否可以仅向 Firefox 浏览器显示单选按钮标签?
谢谢!
您可以隐藏单选按钮,并使用 label:before 伪元素来设置替代单选按钮的样式。此示例仅是 css,但如果需要,您也可以使用背景图像。
\n\ninput[type=radio]{\r\n display:none;\r\n}\r\n\r\ninput[type=radio] + label:before{\r\n content: \'\xe2\x80\xa2\';\r\n display:inline-block;\r\n border-radius: 10px;\r\n width: 16px;\r\n height:16px;\r\n background:#8cf;\r\n color:#8cf;\r\n border: 2px solid #f00;\r\n line-height: 15px;\r\n text-align: center;\r\n font-size:25px;\r\n margin-right: 5px;\r\n}\r\n\r\ninput[type=radio]:checked + label:before{\r\n color: #fff;\r\n}Run Code Online (Sandbox Code Playgroud)\r\n<input type="radio" name="group" id="radio1" /><label for="radio1">radiobutton</label><br />\r\n<input type="radio" name="group" id="radio2" /><label for="radio2">radiobutton</label><br />\r\n<input type="radio" name="group" id="radio3" /><label for="radio3">radiobutton</label><br />\r\n<input type="radio" name="group" id="radio4" /><label for="radio4">radiobutton</label>Run Code Online (Sandbox Code Playgroud)\r\n尝试用这个:
-moz-appearance:none;
Run Code Online (Sandbox Code Playgroud)
在:
#service_type input {
-webkit-appearance:none;
-moz-appearance:none;
height:50px;
width:150px;
padding:10px;
color:white;
margin:5px;
font-size: 18px;
text-align: center;}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5795 次 |
| 最近记录: |