使用nth-child选择多个子元素 [英] Select multiple child elements using nth-child

查看:2139
本文介绍了使用nth-child选择多个子元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

div div p:nth-child(1 to 5)

我如何选择第n个孩子的多个数字,所以我不用写就得到了1到5的孩子元素:

How can I select multiple numbers with the nth-child, so I get the child elements 1 to 5 without having to write:

div div p:nth-child(1),
div div p:nth-child(2),
div div p:nth-child(3),
div div p:nth-child(4),
div div p:nth-child(5) {

}

所以它应该像这样:

div div p:nth-child(1 to 5)

推荐答案

div div p:nth-child(-n+5){

}

这将选择前5个孩子.

这篇关于使用nth-child选择多个子元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆