css - ul li :last-child affects the last li in the second ul

标签 css css-selectors

JsFiddle

我的问题是,当使用伪代码 :last-child 我希望包含 Eli 会受到样式的影响,但是受影响的是 .subNav 中的最后一个 li

我已经尝试过这些(如下),但没有任何效果。

nav ul:first-child li:last-child {border: none;padding-right: 0;}
nav ul:not(.subNav) li:last-child {border: none;padding-right: 0;}

如何让主ul的最后一个li受到影响?

最佳答案

在最后一个 li 之后有一个 div。因此,它不是最后一个 child 。您可以使用 :last-of-type以最后一个 li 为目标:

nav ul li:last-of-type {border: none;padding-right: 0;}

DEMO

关于css - ul li :last-child affects the last li in the second ul,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25762098/

相关文章:

javascript - 使用 js 加载 css 样式表来更新已渲染网页的样式

html - 从另一个 css 类继承

css - 空白和空伪类之间的区别

jquery - 如何检索隐藏按钮的类?

html - 选择器后更改 n 项的样式

jquery - IE7去除背景透明的方法

html - 如何使 div 居中且所有边与包装器等距

css - 多个 DIV,相同的类,如何减少 css 标记?

jquery - 有没有像这样的 jquery 菜单插件?

jquery - 可以在带有 css 类的 Jquery 表中选择