0

As the topic says, I want to set margin :0; on the h3 when the next tag will be h4, else default. I'm trying to avoid having the editors use a <br>, but designers don't seem to get code.

I could a quick JS snippet to do this, but I'm trying to avoid this type of thing with JS.

Here's my raw HTML

<h3>Example Title</h3>
<h4>Sub Title</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
Vucko
  • 20,555
  • 10
  • 56
  • 107
Mark Handy
  • 1,180
  • 1
  • 11
  • 23
  • Something like that? http://www.w3schools.com/cssref/sel_element_pluss.asp – mahatmanich Sep 30 '16 at 12:00
  • 1
    There is no previous selector in CSS. You'll have to use JS. However, you can set `margin-top` on `h4` if he is after `h3` - `h3 + h4 { margin-top: 0 }` – Vucko Sep 30 '16 at 12:02
  • I did further digging, and JS would be the only option. So, that means the content editors need to follow some guidelines. LOL, yeah, like that ever happens. – Mark Handy Sep 30 '16 at 12:07
  • I think you are going about this wrong. If the issue is you want to have suitable spacing between the headings, but don't want to use br tags, then this can be accomplished without a previous-sibling selector. – ESR Sep 30 '16 at 14:16

0 Answers0