Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Z-Index of Material Dropdown component not layering underneath a fixed div when opened

Objective: I would like the Header, Tab Section, and the Radio Button Section to be fixed in a form (see image below). Meaning that they should always be in view, and never have any overlapping elements.

The form looks like the following:

enter image description here

This is working fine when I simply scroll down on the form:

enter image description here

The Problem:

When I open the Angular Material dropdown, it overlaps over the Radio Button Section:

enter image description here

Here is the HTML. The highlighted sections are the elements that I want to be fixated on the form:

enter image description here

And here is the CSS for the 3 sections

//Header:
.module__header {
  position: fixed;
  top: 0px;
  z-index: 1001;
  display: flex;
  height: 35px;
  width: 100%;
  background-color: #082749;
  color: #FFFFFF;
  font-size: 14px;
  font-weight: 500;
  align-items: center;
  justify-content: stretch;
  padding: 0;
  margin-bottom: 0;
}

// Tab Section:
  .mat-tab-label-container {
    position: fixed;
    top: 35px;
    padding-top: 10px;
    z-index: 1001;
    width: 100%;
    background: #fff;
  }

// Radio Button Section:
.timaticFullTextView {
  padding-top: 35px;
  padding-left: 15px;
  padding-bottom: 15px;
  background: #fff;
  z-index: 1001;
  position: fixed;
  width: 100%;
  border-bottom: 1.5px solid gray;
}

I have tried changing the cdk-overlay-container to a z-index of <1001, but that still is overlapping the Radio Button Section.

How can I have the opened dropdown display underneath all 3 sections?

Edit: Adding screenshot to show the cdk-overlay that is giving issues. I have tried removing and lowering the z-index, but it doesn't have any effect enter image description here

like image 773
Kode_12 Avatar asked May 31 '19 00:05

Kode_12


People also ask

How do you use Z-index without position?

Yes: use position:relative; z-index:10 . z-index has no effect for position:static (the default).

Does Z-Index inherit?

No, it isn't inherited. You can see it in MDN article. However, be aware that z-index sets the z-position relatively to the stacking context. And a positioned element with non auto z-index will create an stacking context.

What does a Z-Index do?

The z-index property specifies the stack order of an element. An element with greater stack order is always in front of an element with a lower stack order.


1 Answers

The problem is that mat-tab-body has z-index: 1 and this won't allow your fixed view inside to have a higher elevation. You can remove the z-index from mat-tab-body put then your content without a z-index won't be clickable anymore so you have to add a z-index and position to your not fixed content.

The code would have to look something like this:

<mat-tab>
  <mat-tab-body> <!-- <-- added automatically -->
    <div class="tab-header"></div>
    <div class="tab-content"></div>
  </mat-tab-body>
</mat-tab>
::ng-deep mat-tab-body {
  z-index: unset !important;
}

.tab-header {
  position: fixed;
  z-index: 1001;
}

.tab-content {
  position: relative;
  z-index: 1;
}
like image 172
frido Avatar answered Sep 28 '22 06:09

frido