0
h3 + ul { margin-top: 0; }

This targets ul, is it possible to target h3 instead?

Instead of selecting all uls that appear after a h3, I want to select all h3s that precede a ul

Elmo
  • 6,039
  • 15
  • 68
  • 137

1 Answers1

1

There is no selector that does what you're looking for*.


The "Selectors Level 4" specification is currently in draft phase and is not implemented by any browser that I know of at the time of writing. It introduces the concept of a selector "subject", which would allow you to specify the part of the selector that the styles are applied to:

/* applies to ul */
h3 + ul {
    margin-top: 0;
}

/* applies to h3 */
!h3 + ul {
    margin-top: 0;
}

* yet

zzzzBov
  • 167,057
  • 51
  • 314
  • 358