PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, November 8, 2022

[FIXED] Why is there a gap between the header and the main div?

 November 08, 2022     css, header, html, menu, nav     No comments   

Issue

There is a gap between the header and the main that is the same color as the background color I set for the body tag (black). I've tried making overflow: hidden and margin: 0 but that did not work either.

What is causing this gap?

(.menu does not show if the menu button has not been clicked - so display: none)

body {
  color: #fff;
  font-family: Gotham;
  font-weight: 400;
  background-color: #000;
  margin: 0;
  padding: 0;
  max-width: 100%;
  overflow-x: hidden;
}

main {
  margin: 0;
  padding: 0;
  overflow: hidden;
}

header {
  height: 3.4rem;
  display: grid;
  align-items: center;
  overflow: hidden;
}

.menu {
  display: none;
  overflow-x: none;
  margin-top: 0;
}

.top {
  background-color: var(--purple);
  top: 0;
  margin: 0;
  padding: 0;
}

.top-container {
    margin: 2rem 1rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
}
<header>
  <div class="header-container">
    <div class="left">
      <img src="img/logo.jpg" alt="">
    </div>
    <div class="right">
      <img src="img/user.png" alt="">
      <i class="fa-solid fa-bars fa-xl"></i>
    </div>
  </div>
</header>
<nav class="menu">
  <div class="menu-container">
    <!-- content -->
  </div>
</nav>
<main>
  <section class="top">
    <div class="top-container">
      <!-- content -->
    </div>
  </section>
</main>

How do I get rid of the gap?


Solution

It turns out that all I needed to do was make the top-container margin-top: 0. The margin for the top and bottom before was at 2rem.

So it looked like:

.top-container {
    margin: 0rem 1rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

So to add space between the top of the container and the content, you need to add margin to the actual content not the container.



Answered By - tices
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,204,415

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing