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

Content in body is in navbar

im trying to create a responsive website with html and css
Ive just completed the navbar but ive noticed an issue
the content of my body is overflowing into the navbar

<body>
    <div class="navbar">
        <h1>test</h1>
        <div style="justify-content: space-evenly;display:flex;">
            <a class="test">
                <u><h2>test</h2></u>
            </a>
            <a class="test">
                <u><h2>test</h2></u>
            </a>
            <a class="test">
                <u><h2>test</h2></u>
            </a>
        </div>
    </div>
    <div class="main">
        Test
    </div>
</body>


body {
    height: 100dvh;
    background-attachment: fixed;
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    justify-content: center;
    align-items: center;
}

.navbar {
    position: fixed;
    text-align: center;
    top: 0;
    left: 0;
    width: 100%;
    height: auto;
    justify-content: center;
    align-items: center;
    padding: 0 20px;
    box-sizing: border-box;
}

The div main is inside of the navbar and hidden under it

how do I prevent this ?

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

Ive tried to set a margin but for some reason it still remained inside of the navbar

just a bit further into it

>Solution :

Position fixed changes the way the element occupies the space in the box. Either change the navbar’s position property to static, or add top margin to the .main element

body {
  height: 100dvh;
  background-attachment: fixed;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  justify-content: center;
  align-items: center;
}

.navbar {
  position: static;  // <-- changed fixed to static
  text-align: center;
  top: 0;
  left: 0;
  width: 100%;
  height: auto;
  justify-content: center;
  align-items: center;
  padding: 0 20px;
  box-sizing: border-box;
}
<body>
  <div class="navbar">
    <h1>test</h1>
    <div style="justify-content: space-evenly;display:flex;">
      <a class="test">
        <u><h2>test</h2></u>
      </a>
      <a class="test">
        <u><h2>test</h2></u>
      </a>
      <a class="test">
        <u><h2>test</h2></u>
      </a>
    </div>
  </div>
  <div class="main">
    Test
  </div>
</body>
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