gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 08:16:06 25 4
gpt4 key购买 nike

我找到了一篇 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com