我如何选择其他每个孩子和邻近的孩子?
Image attached for desired result
I want to select in order 2,3 then 6,7 and then 10 Image attached for desired result. So How do I select these with nth-child or something else? It'll go something like this...
(1)(2)
(3)(4)
(5)(6)
(7)(8)
(9)(10)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用以下方式解决此问题:nth-child使用两个公式,一个用于均匀数字,一个用于偶数。这是我建议的一个工作示例:
4n
部分提供了您要寻找的“其他偶数/奇数”部分:它将每4个项目选择一个。-1
和-2
偏移此间隔以匹配所需的数字。使用Offsets+1
和0
时,您可以获得逆行为(选择1、4、5、8、9等)。You could solve this with :nth-child using two formulas, one for the even numbers and one for the even ones. This is a working example of my suggestion:
The
4n
part provides the "every other even/odd" part you're looking for: it will select one every 4 items. The-1
and-2
offset this interval to match the numbers you want. You could get the inverse behaviour (select 1, 4, 5, 8, 9, etc) when using offsets+1
and0