0

My whole question is in the title.

I have side menu which is shown when yellow button clicked. But when sidebar appears the button goes behind it. I need it on the top so that user could click it and close the sidebar. Html markup is complex, so serious changings of markup are not preferable.

I need to put yellow button div on the very top, not the header, header should be behind the sidebar. How to do that? Tried many things, but nothing helped...

<div class="header">
  <div>
    <div class="button">
      close
    </div>
  </div>
</div>
<div class="sidebar">
  fasdf
</div>

.header {
  height: 60px;
  background-color: green;
  top: 0;
  left: 0;
  position: fixed;
  width: 100%;
}
.button {
  height: 60px;
  background-color: yellow;
  width: 60px;
  z-index: 100;
  flex: 1;
}
.sidebar {
  height: 100%;
  width: 100px;
  background-color: pink;
  position: fixed;
  top: 0;
  left: 0;
  flex: 1;
  z-index: 1;
  opacity: .9;
}

https://jsfiddle.net/epwx4s79/4/

John Smith
  • 1,204
  • 3
  • 22
  • 42
  • if you check the duplicate at the very end, you will see that position:fixed create a stacking context so you cannot place the yellow button outside if you don't remove the position:fixed – Temani Afif May 12 '19 at 10:09
  • also note that z-index need to have the element positionned to work, your button is missing at least `position:relative` – Temani Afif May 12 '19 at 10:09

0 Answers0