要解决这个问题,您可以使用 CSS 中的 ':checked' 伪类和兄弟选择器来实现选项被选择后变蓝色的效果。以下是一个示例代码:

HTML:

<input type='radio' name='option' id='option1'>
<label for='option1'>选项1</label>

<input type='radio' name='option' id='option2'>
<label for='option2'>选项2</label>

<input type='radio' name='option' id='option3'>
<label for='option3'>选项3</label>

<div class='options'>
  <div>内容1</div>
  <div>内容2</div>
  <div>内容3</div>
</div>

CSS:

.options div {
  color: black;
}

input[type='radio']:checked ~ .options div {
  color: blue;
}

在上述代码中,我们使用了 `input[type='radio']:checked ~ .options div` 选择器来选中被选择的选项后的 `div` 元素,并将其颜色设置为蓝色。请将上述代码添加到您的 HTML 文件中,并进行相应的调整,以适应您的布局和样式需求。

Element Select 选项被选中后变蓝色的 CSS 实现方法

原文地址: https://www.cveoy.top/t/topic/qvfm 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录