gpt4 book ai didi

html - 自定义单选按钮未显示

转载 作者:行者123 更新时间:2023-11-28 15:12:21 25 4
gpt4 key购买 nike

我已经放置了自定义单选按钮,但单选按钮没有显示。这样安排就可以了

<label>   
<input type="radio" name="gender" />
<span>Female</span>
</label>

为什么它不起作用。这段代码有什么问题吗?

我的 HTML 代码

<div class="radio_btns">
<label><span>Gender</span></label>
<label>
<span>Female</span>
<input type="radio" name="gender" />
</label>
<label>
<span>Male</span>
<input type="radio" name="gender" />
</label>
</div>

CSS 代码

.radio_btns {width:100%; float:left;}
.radio_btns [type="radio"] {border: 0; clip: rect(0 0 0 0); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; width: 1px;}
.radio_btns label {display: block; cursor: pointer; line-height: 2.5;}
.radio_btns [type="radio"] + span {display: block;}
.radio_btns [type="radio"] + span:before {content: ''; display: inline-block; width: 1em; height: 1em; vertical-align: -0.25em; border-radius: 1em; border: 0.125em solid #fff; box-shadow: 0 0 0 0.15em #000; margin-right: 0.75em; transition: 0.5s ease all;}
.radio_btns [type="radio"]:checked + span:before {background: #07eb07; box-shadow: 0 0 0 0.25em #000;}
.radio_btns label {float:left; width:150px;}

What I get with this code

最佳答案

加号是adjacent sibling selector - 这意味着紧随其后的元素,因此在您的情况下,您需要在 input 之后添加一个 span 才能使样式生效:

.radio_btns {
width: 100%;
float: left;
}

.radio_btns [type="radio"] {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}

.radio_btns label {
display: block;
cursor: pointer;
line-height: 2.5;
}

.radio_btns [type="radio"]+span {
display: inline-block;
}

.radio_btns [type="radio"]+span:before {
content: '';
display: inline-block;
width: 1em;
height: 1em;
vertical-align: -0.25em;
border-radius: 1em;
border: 0.125em solid #fff;
box-shadow: 0 0 0 0.15em #000;
margin-right: 0.75em;
transition: 0.5s ease all;
}

.radio_btns [type="radio"]:checked+span:before {
background: #07eb07;
box-shadow: 0 0 0 0.25em #000;
}

.radio_btns label {
float: left;
width: 150px;
}
<div class="radio_btns">
<label><span>Gender</span></label>
<label>
<span>Female</span>
<input type="radio" name="gender" />
<span></span>
</label>
<label>
<span>Male</span>
<input type="radio" name="gender" />
<span></span>
</label>
</div>

关于html - 自定义单选按钮未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48687656/

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