我遇到的问题是我得到了数量可变的子元素。 我的 :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 */
}
关于CSS 选择器 :child(> n)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10316252/