0

I want gui to be on top of poster. Both elements must have fixed positions. It works fine if I set gui position to absolute but fixed doesn't work.

#gui {
  width: 250px;
  height: 50px;
  position: fixed; // If I change to absolute then it works.
  background-color: green;
}

#poster {
  width: 250px;
  height: 250px;
  position: fixed;
  background-color: red;
  z-index: -1;
}
<div id='gui'>
  <div id='poster'></div>
</div>

https://jsfiddle.net/pfpj03f5/

Why isn't this working? Setting z-index to positive numbers on #gui doesn't work either.

Tom
  • 4,257
  • 6
  • 33
  • 49
Martin Dawson
  • 7,455
  • 6
  • 49
  • 92

1 Answers1

2

Because poster is a child element of gui.

Fixed position makes them independent of parent elements anyway, so just move poster out of gui and it works:

<div id='gui'></div>
<div id='poster'></div>

https://jsfiddle.net/eaaz8o2z/

Johannes
  • 64,305
  • 18
  • 73
  • 130