Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I place main element above header and below nav element?

I tried to position the main element above the header and below the nav element, I used the z-index but it doesn’t work properly.

I use position sticky in header and position relative in main element because some stuff uses position absolute.

Do you have any solution for my case?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

header,
nav,
main {width: 100%;}
header{
  height: 10rem;
  position: relative;
  top: 0;
  background: blueviolet;
  z-index: 1;
}
nav {
  height: 4rem;
  background: yellow;
  z-index: 3;
}
main {
  height: 30rem;
  position: relative;
  background: crimson;
  z-index: 2;
}

div {
  display: flex;
}
<header>
  <nav>navbar</nav>
  header
</header>
<main>main</main>

>Solution :

Just re-work your HTML so that it follows that order. If you want your nav element at the top and header at the bottom, don’t nest the nav in the header.

header,
nav,
main {width: 100%;}
header{
  height: 10rem;
  position: relative;
  top: 0;
  background: blueviolet;
  z-index: 1;
}
nav {
  height: 4rem;
  background: yellow;
  z-index: 3;
}
main {
  height: 30rem;
  position: relative;
  background: crimson;
  z-index: 2;
}

div {
  display: flex;
}
<nav>navbar</nav>
<main>main</main>
<header>header</header>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading