html中小于和大于怎么判断,html – CSS nth-child大于和小于

:nth-​​child()不适用于类,它查找元素本身。您需要使用包装器来包装.container div,并使用以下内容:

.wrapper div:nth-child(n+3) {

/* put your styles here... */

}

澄清:nth-​​child()

使用.container:nth-​​child(n 3)可能会也可能不工作。因为:nth-​​child()伪类表示与选择器匹配的第n个子元素(在这种情况下为.container)。

如果.container元素不是其父项的第n个子元素,则不会被选中。

The :nth-child(an+b) pseudo-class notation represents an element

that has an+b-1 siblings before it in the document tree, for any

positive integer or zero value of n, and has a parent element.

考虑这个例子:

1st
2nd
3rd
4th
5th
6th
7th
8th
9th

在这种情况下,.container:nth-​​child(2)将不会选择第二个div.container元素(具有第5个内容)。因为该元素不是其父项的第二个子节点,而是父节点的子树中。

另外,.container:nth-​​child(n3)将会选择所有的div.container元素,因为n从父的子树中的第一个元素开始为0,第一个div.container是其父代的第四个子节点。

n starts from 0

n = 0: (0 + 3) = 3 => 3rd element

n = 1: (1 + 3) = 4 => 4th element

n = 2: (2 + 3) = 5 => 5th element

...

因此,div.container:nth-​​child(n 3)表示匹配div.container选择器的所有第3,第4,第5,…子元素。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值