- This topic is empty.
Viewing 10 posts - 1 through 10 (of 10 total)
Viewing 10 posts - 1 through 10 (of 10 total)
- The forum ‘CSS’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
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.
Any ideas?
Thank you,
Charlie
You can if they’re siblings:
h2 ~ h2{border-bottom: 3px solid red;}
I don’t think you will be able to do this (If they’re not siblings) as CSS cascades.
That could work. I’ll have to limit the total number of posts to display. But that shouldn’t be a problem.
Thank you!
What is the proper way to designate the h2’s you want to style…
: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?
Use:
: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.
You don’t need to designate a range?
@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.
Ahhhh.
Thank you.
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