html - 第 n 个 child (奇数)选择一切

标签 html css

我正在尝试为交替行应用样式,这里是 fiddle 为什么要全选?

li { background: green; }
         li:nth-child(odd) { background: red; }

最佳答案

<Br>在这种情况下也被计算在内。所以你所有的里都变成奇数了。 比如..

  1. li
  2. br
  3. li
  4. br

这就是为什么您的普通 li 选择器自 li:nth-child(odd) { background: red; } 之后不再适用的原因覆盖所有li。 删除 br 标签,它应该没问题。

关于html - 第 n 个 child (奇数)选择一切,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35007564/

相关文章:

php - 用户可以在他们的个人资料描述中使用 html、css、javascript、php 等

css - Google Chrome "Failed parsing SourceMap": css. map (Web Essential)

html - 图片上传到 godaddy 时未加载

Css - 对齐 <Div>

javascript - 如何添加 arr include many "src"of images into a source of image tag

html - OverFlow 隐藏在不同的浏览器中显示不正确

html - 将复选框与表单的其余部分对齐/样式化

html - 无法设置div的背景颜色

jquery - 带有 jquery 标题的 cycle2 幻灯片不合适

html - break div 溢出 : hidden while retaining page structure