[英]Javascript: How to use adjacent sibling selector in jss with <input type=radio> // change color when clicked
I am trying to change the color of the label on a radio button in jss when it is clicked.我试图在单击 jss 中的单选按钮时更改 label 的颜色。 This is what I have so far in Form.jsx:这是我目前在 Form.jsx 中的内容:
<section className={classes.buttons} data-toggle="buttons">
<label className={classes.btn}>
<input type="radio" name="options" id="option1" checked/>
<span>9th grade</span>
</label>
<label className={classes.btn}>
<input type="radio" name="options" id="option2"/> <span>10th grade</span>
</label>
<label className={classes.btn}>
<input type="radio" name="options" id="option3"/> <span>11th grade</span>
</label>
<label className={classes.btn}>
<input type="radio" name="options" id="option4"/> <span>12th grade</span>
</label>
</section>
In my formStyles.js file,在我的 formStyles.js 文件中,
buttons : {
display: 'grid',
gridGap: '50px',
gridTemplateColumns: 'auto auto',
background: 'rgba(255 , 255, 255, 0.25)',
padding: '30px',
margin: '30px 100px 10px 100px',
zIndex: '1',
"& input[type = radio]": {
opacity: '0',
position: 'fixed',
width: '0',
"&:checked &span" : {
display: 'none',
color: 'blue',
fontSize: '30px',
},
},
"& label": {
backgroundColor: '#BC98EE',
zIndex: '2',
color: 'white',
},
},
It works only when I do "&:checked" but not when I add "&span".它仅在我执行“&:checked”时有效,但在添加“&span”时无效。 In fact, it does not run anything under "&:checked &span" when I add "&span".事实上,当我添加“&span”时,它不会在“&:checked &span”下运行任何东西。 Any suggestions?有什么建议么?
The span is a sibling of the checked input, not a descendant.跨度是检查输入的兄弟,而不是后代。
See: Adjacent Sibling Combinator请参阅: 相邻兄弟组合器
.buttons { padding: 30px; }.buttons input:checked+span { color: blue; }
<section class="buttons"> <label> <input type="radio" name="options" id="option1" checked /> <span>9th grade</span> </label> <label> <input type="radio" name="options" id="option2"> <span>10th grade</span> </label> <label> <input type="radio" name="options" id="option3"/> <span>11th grade</span> </label> <label> <input type="radio" name="options" id="option4" /> <span>12th grade</span> </label> </section>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.