Is there a way to style any <h1>
element(s) that come after an <h2>
element using only CSS?
I've searched through countless pages of CSS documentation, trying to figure out if it's possible to target specific elements that appear AFTER other elements, whether they are in the same branch or a different branch of the HTML markup.
It appears that existing selectors and pseudo-classes are limited to identifying elements that are:
- Siblings
- Children
- Descendants
I am looking for relationships beyond these traditional ones:
- Nieces
- Nephews
- Cousins
- Third cousins twice removed
- Granduncles
- And so on...
These elements would logically appear AFTER a specific element in the HTML structure. However, I cannot predict:
- The exact nature of the relationship
- How many instances of the desired elements there will be.
Example 1 - Niece
<div>
<h2>2</h2>
<div>
<h1>1</h1>
</div>
</div>
Example 2 - Cousin
<div>
<div>
<h2>2</h2>
</div>
<div>
<h1>1</h1>
</div>
</div>
Example 3 - Granduncle
<div>
<div>
<div>
<h2>2</h2>
</div>
</div>
<h1>1</h1>
</div>