CSS 选择器 :child(> n)?

标签 css css-selectors

我遇到的问题是我得到了数量可变的子元素。 我的 :last-child :first-child 规则只适用于至少有 3 个 child 的情况

我试过 :only-child,当只有 1 个 child 时,它可以覆盖 :last- 和 :first-child,但是当我有 2 个 child 时,我遇到了问题。是否存在某种选择器,它仅适用于子级数多于 n 的情况?

最佳答案

使用 :nth-child(n+3) 选择器(其中 3 是第 n 个最 child 子)。

:last-child:nth-child(n+3) {
     /* Selects the last child which is at least the third child */
}

演示:http://jsfiddle.net/vCZ9A/

关于CSS 选择器 :child(> n)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10316252/

相关文章:

html - firefox 图片加载问题

javascript - testcafe 选择器未找到 'div' 元素

css - nth-of-type 与 nth-child

javascript - 禁用按钮和按钮悬停显示(不同的)警报/错误消息,具体取决于 CSS 的状态

html - 嵌套 li(列表)项的文本装饰

jquery - 使用 jQuery 在 CSS 中设置水平滚动条样式

html - 跨浏览器图像

python - 使用 Selenium 单击 "selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element"按钮时出现 'Next'

css - 选择元素时,插入符号 ^ 在 css 中的用途是什么?

html - 为什么我的第一个子选择器不能处理具有指定类的选择中的第一个元素?