Reputation: 307
I need some help with writing a nth-child selector in CSS for the following situations
Children #1, #4, #7, #10, ... should have specific css
Children #2, #3, #5, #6, ... should have some other specific css
Had this (:nth-child(3n-2)) for the first, but can't come up with something for the second.
Thanks!
Upvotes: 1
Views: 179
Reputation: 724452
Are children #2, #3, #5, #6, ... just anything other than children #1, #4, #7, #10, ...?
If so, you can either just create a rule for all children in general, then override the styles for children #1, #4, #7, #10, ... like this:
.child {
/* All children */
}
.child:nth-child(3n-2) {
/* Override for #1, #4, #7, #10, ... */
}
Or if you need to specifically apply styles to those children without overriding, you can negate the same :nth-child()
with :not()
in a separate rule:
.child:nth-child(3n-2) {
/* #1, #4, #7, #10, ... */
}
.child:not(:nth-child(3n-2)) {
/* #2, #3, #5, #6, ... */
}
Upvotes: 3