Reputation: 195
div div p:nth-child(1 to 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) {
}
So it should look like this:
div div p:nth-child(1 to 5)
Upvotes: 11
Views: 16962
Reputation: 44581
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){
}
Or
div div p:nth-child(-n+5){
}
Upvotes: 5
Reputation: 1055
I've attached a link to a JSFiddle that should do what you are asking, but it should look something like this:
li:nth-child(-n+5){
color: red;
}
Upvotes: 5
Reputation: 7463
div div p:nth-child(n+1):nth-child(-n+5){
}
will select elements 1 to 5
Upvotes: 11