gpt4 book ai didi

html - 单选按钮选中的属性不起作用

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

我正在尝试在 radio 的标签上悬停效果,因为它工作正常,但我想要实现的是:

如果我选择一个单选按钮,相应的标签应该有一些背景色

我尝试了很多组合,但它对我不起作用。任何帮助将不胜感激。

.checkout_beautify {
font-size: 16px;
line-height: 45px;
font-weight: bold;
border: 1px dotted black;
-webkit-transform: scale(1.1);
-moz-transform: scale(1.1);
-o-transform: scale(1.1);
-ms-transform: scale(1.1);
transform: scale(1.1);
transition: all 400ms;
border-radius: 25px;
text-align: center;
}
.checkout_beautify:hover {
font-size: 16px;
line-height: 45px;
font-weight: bold;
border: 1px dotted black;
border-radius: 25px 4px 25px 4px;
background: #1B1B1B;
color: #ffffff;
transition: all 4ms;
text-align: center;
}
label[for=bank_transfer]:hover {
font-size: 16px;
line-height: 45px;
font-weight: bold;
border: 1px dotted black;
border-radius: 25px 4px 25px 4px;
background: #1B1B1B;
color: #ffffff;
transition: all 4ms;
text-align: center;
}
label[for=icicipg]:hover {
font-size: 16px;
line-height: 45px;
font-weight: bold;
border: 1px dotted black;
border-radius: 25px 4px 25px 4px;
background: #1B1B1B;
color: #ffffff;
transition: all 4ms;
text-align: center;
}
/*COMBINATIONS I TRIED*/

.radio input[type="radio"]:checked {
background: pink !important;
}
.radio input[type="radio"]:checked ~ * {
background: pink !important;
}
<table class="radio">
<tbody>
<tr class="highlight">
<td>
<input type="radio" name="payment_method" value="payu" id="payu" checked="checked">
</td>
<td>
<label for="payu">
<h3 class="checkout_beautify"><b>PAYU MONEY - (Credit/Debit/NetBanking)</b></h3>
</label>
</td>
<td></td>
</tr>
<tr class="highlight">
<td>
<input type="radio" name="payment_method" value="icicipg" id="icicipg">
</td>
<td>
<label for="icicipg">ICICI PAYMENT GATEWAY - (Credit/Debit)</label>
</td>
<td></td>
</tr>
<tr class="highlight">
<td>
<input type="radio" name="payment_method" value="citrus" id="citrus">
</td>
<td>
<label for="citrus">
<h3 class="checkout_beautify"><b>CITRUS - (Netbanking)</b></h3>
</label>
</td>
<td></td>
</tr>
<tr class="highlight">
<td>
<input type="radio" name="payment_method" value="bank_transfer" id="bank_transfer">
</td>
<td>
<label for="bank_transfer">
<h3><b>DEPOSIT IN BANK</b></h3>
</label>
</td>
<td></td>
</tr>
</tbody>
</table>

最佳答案

您必须更改标签父级并放入相同的 <td>所以CSS适用于它,

.checkout_beautify {
font-size: 16px;
line-height: 45px;
font-weight: bold;
border: 1px dotted black;
-webkit-transform: scale(1.1);
-moz-transform: scale(1.1);
-o-transform: scale(1.1);
-ms-transform: scale(1.1);
transform: scale(1.1);
transition: all 400ms;
border-radius: 25px;
text-align: center;
}
.checkout_beautify:hover {
font-size: 16px;
line-height: 45px;
font-weight: bold;
border: 1px dotted black;
border-radius: 25px 4px 25px 4px;
background: #1B1B1B;
color: #ffffff;
transition: all 4ms;
text-align: center;
}
label[for=bank_transfer]:hover {
font-size: 16px;
line-height: 45px;
font-weight: bold;
border: 1px dotted black;
border-radius: 25px 4px 25px 4px;
background: #1B1B1B;
color: #ffffff;
transition: all 4ms;
text-align: center;
}
label[for=icicipg]:hover {
font-size: 16px;
line-height: 45px;
font-weight: bold;
border: 1px dotted black;
border-radius: 25px 4px 25px 4px;
background: #1B1B1B;
color: #ffffff;
transition: all 4ms;
text-align: center;
}
/*CHANGE FOLLOWING*/
.radio input[type="radio"]:checked + label {
background: pink;
}
.radio input[type="radio"]:checked + label * {
background: pink;
}

label { float:left; clear:none; }
input[type=radio] { float:left; clear:none; margin: 2px 0 0 20px; }
<table class="radio">
<tbody>
<tr class="highlight">
<td>
<input type="radio" name="payment_method" value="payu" id="payu" checked="checked">

<label for="payu">
<h3 class="checkout_beautify"><b>PAYU MONEY - (Credit/Debit/NetBanking)</b></h3>
</label>
</td>
<td></td>
</tr>
<tr class="highlight">
<td>
<input type="radio" name="payment_method" value="icicipg" id="icicipg">

<label for="icicipg">ICICI PAYMENT GATEWAY - (Credit/Debit)</label>
</td>
<td></td>
</tr>
<tr class="highlight">
<td>
<input type="radio" name="payment_method" value="citrus" id="citrus">

<label for="citrus">
<h3 class="checkout_beautify"><b>CITRUS - (Netbanking)</b></h3>
</label>
</td>
<td></td>
</tr>
<tr class="highlight">
<td>
<input type="radio" name="payment_method" value="bank_transfer" id="bank_transfer">

<label for="bank_transfer">
<h3><b>DEPOSIT IN BANK</b></h3>
</label>
</td>
<td></td>
</tr>
</tbody>
</table>

您必须使用 css 才能进行适当的布局。


如果你想在你的代码中使用 Jquery 那么它很好,你可以很容易地实现它。喜欢,

DEMO FIDDLE

关于html - 单选按钮选中的属性不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33952203/

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