Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Div with position: fixed not displaying inside div with position: absolute in Safari

I have a fixed position div inside an absolutely positioned div. In Chrome and Firefox the inner div is displayed, but in OSX Safari 10, it is not.

JSFiddle

.outer {
  margin-top: 21px;
  position: absolute;
  background: red;
  overflow: hidden;
  z-index: 1;
  box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.2);
  max-height: 100vh;
}

.inner {
  display: inline;
  overflow: hidden;
  position: fixed;
  background-color: blue;
  max-width: 100vw;
}
<div class="outer">
  <p>Inner Div</p>
  <div class="inner">
    <p>Outer Div</p>
  </div>
</div>

In the fiddle, changing the outer div's position property to either static or sticky means that the inner div is displayed. But these position's aren't suitable for my situation.

Is there a way to get the inner div to display in Safari without changing the divs' positions?

like image 853
Runny Yolk Avatar asked Jan 27 '17 19:01

Runny Yolk


People also ask

How do you handle position fixed inside a div?

Set everything up as you would if you want to position: absolute inside a position: relative container, and then create a new fixed position div inside the div with position: absolute , but do not set its top and left properties. It will then be fixed wherever you want it, relative to the container.

What is the difference between position fixed and sticky?

A sticky element toggles between relative and fixed , depending on the scroll position. It is positioned relative until a given offset position is met in the viewport - then it "sticks" in place (like position:fixed).

What is the opposite of position absolute in CSS?

position:static; , position:absolute; , and position:relative; are the alternatives to position:fixed; . There isn't a definitive opposite, because relative , absolute , static , and fixed have different properties to behave differently.

How does position relative work?

position: relative; changes the position of the element relative to the parent element and relative to itself and where it would usually be in the regular document flow of the page. This means that it's relative to its original position within the parent element.


1 Answers

Just before submitting this question I came across the answer. Having written the whole thing out though, I'm posting it in case some other poor soul has the same problem:

The simple solution is to remove the z-index: 1; rule on the parent div. It doesn't make any difference in Chrome, FireFox, or any mobile browsers I tested, but it makes all the difference in Safari.

NOTE: Above is the answer which was posted by the Question Author in the question itself, just copy and pasting here so it can easily get visible for other users.

like image 147
Sami Ahmed Siddiqui Avatar answered Oct 19 '22 22:10

Sami Ahmed Siddiqui