我將自定義CSS添加到一個工具中,該工具為我生成HTML內(nèi)容。不幸的是,看起來該工具會生成單選按鈕(& lt輸入類型= & quot收音機(jī)& quot)在a & lt表單& gt元素。這導(dǎo)致了一些問題,因為正如在回答另一個StackOverflow問題時提到的,如果您沒有& lt表單& gt元素,則不能應(yīng)用以下代碼:
input[type="radio"]:checked+label {
background: yellow;
}
下面是一個代碼示例:
input[type="radio"]:checked+label {
background: yellow;
}
<div class="apt-survey-multi-choice-radio-answers">
<label class="apt-survey-multi-choice-radio">
<input type="radio" value="d45ec94d-88cb-43bc-b4c9" placeholder="" class="" name="apt-trigger-radio-8c027e80-2df7-494a-a3a5" tabindex="31767">
<div class="apt-survey-multi-choice-radio-label">
<div class="multi-survey-answer">
<meta charset="utf-8">
<style type="text/css">
<!--td {border: 1px solid #cccccc;}br {mso-data-placement:same-cell;}
-->
</style>
<span data-sheets-userformat="{"2":515,"3":{"1":0},"4":{"1":2,"2":14281427},"12":0}" data-sheets-value="{"1":2,"2":"Marketing - Individual Contributor"}" style="font-size:10pt;font-family:Arial;font-style:normal;">
<meta charset="utf-8">
<style type="text/css">
<!--td {border: 1px solid #cccccc;}br {mso-data-placement:same-cell;}
-->
</style>
<span data-sheets-userformat="{"2":515,"3":{"1":0},"4":{"1":2,"2":13228792},"12":0}" data-sheets-value="{"1":2,"2":"Individual"}" style="font-size:10pt;font-family:Arial;font-style:normal;">Individual</span>
</span>
</div>
</div>
</label>
<label class="apt-survey-multi-choice-radio">
<input type="radio" value="ae74981b-6395-4718-89ca" placeholder="" class="" name="apt-trigger-radio-8c027e80-2df7-494a-a3a5" tabindex="31768">
<div class="apt-survey-multi-choice-radio-label">
<div class="multi-survey-answer">
<meta charset="utf-8">
<style type="text/css">
<!--td {border: 1px solid #cccccc;}br {mso-data-placement:same-cell;}
-->
</style>
<span data-sheets-userformat="{"2":515,"3":{"1":0},"4":{"1":2,"2":14281427},"12":0}" data-sheets-value="{"1":2,"2":"Product Marketing - Individual Contributor"}" style="font-size:10pt;font-family:Arial;font-style:normal;">Manager</span>
</div>
</div>
</label>
<label class="apt-survey-multi-choice-radio">
<input type="radio" value="c6a9fdfd-aed4-4bb9-9300" placeholder="" class="" name="apt-trigger-radio-8c027e80-2df7-494a-a3a5" tabindex="31769">
<div class="apt-survey-multi-choice-radio-label">
<div class="multi-survey-answer">
<meta charset="utf-8">
<style type="text/css">
<!--td {border: 1px solid #cccccc;}br {mso-data-placement:same-cell;}
-->
</style>
<span data-sheets-userformat="{"2":515,"3":{"1":0},"4":{"1":2,"2":14281427},"12":0}" data-sheets-value="{"1":2,"2":"Finance - Individual Contributor"}" style="font-size:10pt;font-family:Arial;font-style:normal;">
<meta charset="utf-8">
<style type="text/css">
<!--td {border: 1px solid #cccccc;}br {mso-data-placement:same-cell;}
-->
</style>
<span data-sheets-userformat="{"2":515,"3":{"1":0},"4":{"1":2,"2":13228792},"12":0}" data-sheets-value="{"1":2,"2":"Director"}" style="font-size:10pt;font-family:Arial;font-style:normal;">Director</span>
</span>
</div>
</div>
</label>
<label class="apt-survey-multi-choice-radio">
<input type="radio" value="285ddfff-4be4-4c23-9f26" placeholder="" class="" name="apt-trigger-radio-8c027e80-2df7-494a-a3a5" tabindex="31770">
<div class="apt-survey-multi-choice-radio-label">
<div class="multi-survey-answer">
<meta charset="utf-8">
<style type="text/css">
<!--td {border: 1px solid #cccccc;}br {mso-data-placement:same-cell;}
-->
</style>
<span data-sheets-userformat="{"2":515,"3":{"1":0},"4":{"1":2,"2":14281427},"12":0}" data-sheets-value="{"1":2,"2":"CSM - Manager"}" style="font-size:10pt;font-family:Arial;font-style:normal;">
<meta charset="utf-8">
<style type="text/css">
<!--td {border: 1px solid #cccccc;}br {mso-data-placement:same-cell;}
-->
</style>
<span data-sheets-userformat="{"2":515,"3":{"1":0},"4":{"1":2,"2":13228792},"12":0}" data-sheets-value="{"1":2,"2":"VP / SVP"}" style="font-size:10pt;font-family:Arial;font-style:normal;">VP / SVP</span>
</span>
</div>
</div>
</label>
<label class="apt-survey-multi-choice-radio">
<input type="radio" value="d99a91b3-ac39-4534-bf6b" placeholder="" class="" name="apt-trigger-radio-8c027e80-2df7-494a-a3a5" tabindex="31771">
<div class="apt-survey-multi-choice-radio-label">
<div class="multi-survey-answer">
<meta charset="utf-8">
<style type="text/css">
<!--td {border: 1px solid #cccccc;}br {mso-data-placement:same-cell;}
-->
</style>
<span data-sheets-userformat="{"2":515,"3":{"1":0},"4":{"1":2,"2":13228792},"12":0}" data-sheets-value="{"1":2,"2":"C Level"}" style="font-size:10pt;font-family:Arial;font-style:normal;">C Level</span>
</div>
</div>
</label>
</div>
您的選擇器輸入[type = & quot;收音機(jī)& quot]:checked + label正在查找與a :checked單選輸入直接同級的標(biāo)簽,但您的標(biāo)記實際上是
<label class="apt-survey-multi-choice-radio">
<input type="radio" ...>
...
</label>
因此,您需要將包含:checked radio輸入的標(biāo)簽作為目標(biāo),您可以使用:has()
label:has([type="radio"]:checked) {
background: yellow;
}
<label>
<input type="radio" />
Label
</label>