0

I know the plus sign + selects the second of 2 elements that are next but not in one another. Is there a selector for the first element?

I have 2 headings right after one another. h3 then h4. I want to remove the bottom margin from the h3 if an h4 follows. Is something like that possible or do I need to just provide a negative top margin to the h4?

rudtek
  • 373
  • 2
  • 17
  • Possible duplicate https://stackoverflow.com/questions/1817792/is-there-a-previous-sibling-css-selector – samb102 Mar 13 '19 at 17:14

2 Answers2

2

Quoting CSS tricks:

Let's be clear here, just in case someone is finding this from a search engine: there are no parent selectors in CSS, not even in CSS3.

https://css-tricks.com/parent-selectors-in-css/ This article lays out a proposal for a possible parent selector, but due to various performance reasons, browsers would find it difficult to implement

So, the best you can do is negative margins. That's actually a fairly decent solution

h3 + h4 {
 margin-top: -10px;
}
Palash Karia
  • 670
  • 4
  • 10
1

It is not possible to style on siblings to come.

You can use a negative margin on the h4 after an h3

J.T. Houtenbos
  • 956
  • 7
  • 17