css - 反转将颜色应用于 sibling 的方向

标签 css

input:checked ~ label {
    color: red;
}
<input type='radio' name='color'>
<label>black</label>
<input type='radio' name='color'>
<label>green</label>
<input type='radio' name='color'>
<label>yellow</label>
<input type='radio' name='color'>
<label>red</label>
<input type='radio' name='color'>
<label>blue</label>
<input type='radio' name='color'>
<label>gray</label>
<input type='radio' name='color'>
<label>azure</label>
<input type='radio' name='color'>
<label>white</label>

如何使用 color: red 反转为 labels 着色的方向,现在,当我点击 black 时,一切都得到了color: red,但我想要反过来,所以当我点击 white 时,所有内容都变成了 color: red

最佳答案

你可以像这样考虑 flexbox 和倒序:

div {
  display: flex;
  flex-direction: row-reverse;
}

input:checked~label {
  color: red;
}

input:first-child {
  margin-right:auto;
}
<div>
  <input type='radio' name='color'>
  <label>white</label>
  <input type='radio' name='color'>
  <label>azure</label>
  <input type='radio' name='color'>
  <label>gray</label>
  <input type='radio' name='color'>
  <label>blue</label>
  <input type='radio' name='color'>
  <label>red</label>
  <input type='radio' name='color'>
  <label>yellow</label>
  <input type='radio' name='color'>
  <label>green</label>
  <input type='radio' name='color'>
  <label>black</label>
</div>

关于css - 反转将颜色应用于 sibling 的方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49263960/

相关文章:

html - 如果选中复选框,则更改标签颜色;如果未选中复选框,则更改标签颜色

html - 带有省略号的动态文本旁边的图标

html - 2x2 框旁边 1 个大 2x2 大小框使用 css

css - Firefox css 表格单元格不像其他浏览器那样响应位置为 :absolute

javascript - 禁用表数据中控件的单击事件

javascript - css背景在div高度重置时重复

html - 如何在视差滚动图像上放置文本

html - 将网格元素与网格模板列对齐

javascript - 在一个单词动画时移动文本

javascript - 使用 jqprint 使用 CSS 打印特定的 DIV