Is it possible to Target with CSS all h2 on a wordpress site EXCEPT first one on a page?
I would like to add some kind of styling to the h2 title tags on a wordpress page to visually separate the posts, but adding margin or padding to the first one on the page moves the top of page out of alignment.
@charlie, why would you need to designate range? :nth-of-type isn't even built for ranges, you can only plug in basic equations. Also, your :nth-of-type(2-10) wouldn't be "The second through tenth" it would be "Two minus ten".
Just do this:
h2 { color: #fff; }
h2:nth-of-type(n+2) { color: #333; }
Or whatever those styles should be. The first style would target all H2's and the second will target all H2's other than the first.
Yes, :nth-child() takes "n", sets it to 0, solves the equation, and then applies the style to the element of that number in order. And then it sets "n" to 1, solves the equation... etc etc. and it does that over and over again so it applies to all
I would like to add some kind of styling to the h2 title tags on a wordpress page to visually separate the posts, but adding margin or padding to the first one on the page moves the top of page out of alignment.
Any ideas?
Thank you,
Charlie
I don't think you will be able to do this (If they're not siblings) as CSS cascades.
Read about it here
H2:nth-of-type(2) {...your styling...}
Thank you!
:nth-of-type(2-10) would be the 2nd through 10th h2?
or (2-*) would be the 2nd through all present h2's?
or something else?
:nth-of-type(n+2)
n=0, then it targets the second.
n=1, then it targets the third.
n=2, then it targets the forth.
etc.
I think you guys were over thinking this.
or you could again target all the h2s and override using a descendant selector or child selector. Some code would help us show you the best route.
Just do this:
Or whatever those styles should be. The first style would target all H2's and the second will target all H2's other than the first.
Thank you.