gpt4 book ai didi

css - Radiobutton 仅适用于一种形式,其他形式不能

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

我正在尝试修改输入类型 radio 的输入样式,并且我有两种不同形式的 radio 输入。但 radio 输入仅适用于第一种形式,而第二种形式无效。我仍然对为什么不在第二个上工作这个问题感到困惑。

请帮帮我。提前致谢

例如:https://jsfiddle.net/devefrontend/vaqdsmjk/10/

<input type="radio" name="roundtrip" id="oneway" value="oneway" checked="">
<label for="oneway">Oneway</label>

[type="radio"]:checked,
[type="radio"]:not(:checked) {
position: absolute;
left: -9999px;
}

[type="radio"]:checked + label,
[type="radio"]:not(:checked) + label {
position: relative;
padding-left: 28px;
cursor: pointer;
line-height: 20px;
display: inline-block;
color: #666;
}

[type="radio"]:checked + label:before,
[type="radio"]:not(:checked) + label:before {
content: '';
position: absolute;
left: 0;
top: 0;
width: 18px;
height: 18px;
border: 1px solid #ddd;
border-radius: 100%;
background: #fff;
}

[type="radio"]:checked + label:after,
[type="radio"]:not(:checked) + label:after {
content: '';
width: 12px;
height: 12px;
background: #F87DA9;
position: absolute;
top: 4px;
left: 4px;
border-radius: 100%;
-webkit-transition: all 0.2s ease;
transition: all 0.2s ease;
}

[type="radio"]:not(:checked) + label:after {
opacity: 0;
-webkit-transform: scale(0);
transform: scale(0);
}

[type="radio"]:checked + label:after {
opacity: 1;
-webkit-transform: scale(1);
transform: scale(1);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

<div role="tabpanel" class="tab-pane active" id="flights">
<form name="flight" method="GET" action="" id="searchFlights" class="form-inline">
<ul class="radio-list">
<li id="radioFlights">
<input type="radio" name="roundtrip" id="oneway" value="oneway" checked="">
<label for="oneway">Oneway</label>
</li>
<li id="radioFlights">
<input type="radio" name="roundtrip" id="return" value="return">
<label for="return">Return</label>
</li>
</ul>
</form>
</div>
<div role="tabpanel" class="tab-pane" id="trains">
<form name="train" method="GET" action="" id="searchTrains" class="form-inline">
<ul class="radio-list">
<li id="radioTrains">
<input type="radio" name="roundtrip" id="oneway" value="oneway" checked="">
<label for="oneway">Oneway</label>
</li>
<li id="radioTrains">
<input type="radio" name="roundtrip" id="return" value="return">
<label for="return">Return</label>
</li>
</ul>
</form>
</div>

最佳答案

Id 必须是唯一的。因此,请在 radio 输入中提供唯一的 id

[type="radio"]:checked,
[type="radio"]:not(:checked) {
position: absolute;
left: -9999px;
}

[type="radio"]:checked + label,
[type="radio"]:not(:checked) + label {
position: relative;
padding-left: 28px;
cursor: pointer;
line-height: 20px;
display: inline-block;
color: #666;
}

[type="radio"]:checked + label:before,
[type="radio"]:not(:checked) + label:before {
content: '';
position: absolute;
left: 0;
top: 0;
width: 18px;
height: 18px;
border: 1px solid #ddd;
border-radius: 100%;
background: #fff;
}

[type="radio"]:checked + label:after,
[type="radio"]:not(:checked) + label:after {
content: '';
width: 12px;
height: 12px;
background: #F87DA9;
position: absolute;
top: 3px;
left: 3px;
border-radius: 100%;
-webkit-transition: all 0.2s ease;
transition: all 0.2s ease;
}

[type="radio"]:not(:checked) + label:after {
opacity: 0;
-webkit-transform: scale(0);
transform: scale(0);
}

[type="radio"]:checked + label:after {
opacity: 1;
-webkit-transform: scale(1);
transform: scale(1);
}
ul{
list-style:none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

<div role="tabpanel" class="tab-pane active" id="flights">
<form name="flight" method="GET" action="" id="searchFlights" class="form-inline">
<ul class="radio-list">
<li id="radioFlights">
<input type="radio" name="roundtrip" id="oneway" value="oneway" checked="">
<label for="oneway">Oneway</label>
</li>
<li id="radioFlights">
<input type="radio" name="roundtrip" id="return" value="return">
<label for="return">Return</label>
</li>
</ul>
</form>
</div>
<div role="tabpanel" class="tab-pane" id="trains">
<form name="train" method="GET" action="" id="searchTrains" class="form-inline">
<ul class="radio-list">
<li id="radioTrains">
<input type="radio" name="roundtrip" id="oneway2" value="oneway" checked="">
<label for="oneway2">Oneway</label>
</li>
<li id="radioTrains">
<input type="radio" name="roundtrip" id="return2" value="return">
<label for="return2">Return</label>
</li>
</ul>
</form>
</div>

关于css - Radiobutton 仅适用于一种形式,其他形式不能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47299436/

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