Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weird margin-bottom behavior with Safari on iOS

I have something like this in my body (simplified)

<div id="container">
  <article>
    text
  </article>
</div>

with the css

#container > article
  margin-bottom: 50px
  overflow: auto

article
  display: block

On all browsers the margin-bottom is displayed but Safari which seems to collapse it.

I read a lot about this issue, but the overflow: auto does not help right away or any other tricks.

Where things get actually weird is if I move the margin-bottom to the article definition in the css, in this case Safari displays the margin..

#container > article
  /* nothing remains here */

article
  display: block
  margin-bottom: 50px
  overflow: auto

This is not what I want since it affects all the article tags.

If someone could explains me this, and have a workaround to actually make Safari behaves as expected, that would be much appreciated.

like image 274
Sylver Avatar asked Oct 23 '25 19:10

Sylver


1 Answers

I experienced this on other browser as well. It seems that the margin-bottom does not work "if there is nothing to bounce from".

My solution always was to add a small padding to the parent element. Then the margin bounces on the padding.

So try adding:

#container {
  padding-bottom: 1px;
}
like image 108
LinkinTED Avatar answered Oct 25 '25 10:10

LinkinTED