The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Child then adjacent selector? Re: Child then adjacent selector?


Hi mate,

Cheers for that. Don’t think I explained it correctly though…

Basically, when you first view a list of posts in WordPress you get the h2’s with links inside. The next paragraph element is the post date.

Now, when you click on the h2 with the link inside it and go to the next page (the single post view) you get an h2 with the post title BUT no date underneath, so with the adjacent selector it makes the whole first paragraph #5f5f5f :(

I hope that makes some more sense…

Basically the difference between the two is:


Fillz, 15 Bell Street, Reigate

February 10th, 2010

Fillz is a small sandwich bar and coffee shop…

…for the main page (with the anchor in the h2). Then for the single post page:


Fillz, 15 Bell Street, Reigate

Fillz is a small sandwich bar and…

So, I need to find a way of targeting the paragraph only if it’s preceded by an h2 with an anchor inside.

Something like: h2 > a + p { color: #5f5f5f }, so that if there’s no anchor in the h2 don’t make the next paragraph element #5f5f5f.

I know it’s picky but I was just wondering whether CSS could do this :)