If you want to hide certain p
elements, you can utilize the nth-child(n+x)
selector in this way:
p:nth-child(n+6) {
display:none;
}
Check out this example on a JSFiddle, where all elements starting from the 6th are colored red.
The expression n+6
represents the formula an+b
(refer to the specs and MDN). In this case, it simplifies to:
1n+6
This translates to values like 6,7... for different iterations of n
. By adjusting the value of b
, we can create intervals like:
2n+6
Now, for different values of n
, such as 0,1, the sequence will be 6,8,10, etc., targeting every other p
tag starting from the 6th one.