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

Space over Navbar

I’ve got a question. I was trying to code a navbar. It’s working perfectly except for the fact that over the navbar there is a big space. So that the navbar is in the middle of the page. I’ve got no clue what the mistake could be. If u got an idea of what the problem could be and how to solve it, I Would be very pleased. Otherwise, I would be happy to get improvement tips for my code.

.navbar {
  position: fixed;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: justify;
  -ms-flex-pack: justify;
  justify-content: space-between;
  top: 20%;
  width: 100%;
  height: 70px;
  background-color: black;
  -webkit-box-shadow: 0 0 10px var(--shadow);
  box-shadow: 0 0 10px var(--shadow);
  color: white;
  margin-top: 2px;
}

.navbar-nav {
  width: 40%;
  height: 100%;
  padding: 0 7%;
  margin: 0;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: space-evenly;
  -ms-flex-pack: space-evenly;
  justify-content: space-evenly;
  list-style: none;
}

.navbar-nav .nav-item {
  text-align: center;
}

.navbar-nav .nav-item .item-link {
  position: relative;
  width: 100%;
  padding: 15px 20px;
  color: var(--white-smoke);
  text-decoration: none;
  border-radius: 5px;
  border: 1px solid #0e0e0e00;
}

.navbar-nav .nav-item .item-link:hover {
  background-color: var(--shadow);
  border: 1px solid #4e4e4e4d;
}

.navbar-nav .c:hover #drop-down {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
}

.navbar-nav .c:focus-within #drop-down {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
}

.navbar-nav .c #drop-down {
  position: absolute;
  width: -webkit-fit-content;
  width: -moz-fit-content;
  width: fit-content;
  display: none;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  flex-direction: column;
  top: 60px;
  background-color: var(--white-smoke);
  padding: 30px 0;
  border-radius: 5px;
  text-align: left;
  -webkit-box-shadow: 0 0 10px var(--shadow);
  box-shadow: 0 0 10px var(--shadow);
  -webkit-transform: translateX(-10%);
  transform: translateX(-10%);
}

.navbar-nav .c #drop-down .clinks {
  display: block;
  color: #000;
  padding: 5px 0;
  text-decoration: none;
  padding: 10px 50px 10px 20px;
}

.navbar-nav .c #drop-down .clinks i {
  padding: 0 2px;
}

.navbar-nav .c #drop-down .clinks:hover {
  background-color: var(--shadow);
}

@media screen and (max-width: 1000px) {
  .navbar #brand {
    display: none;
  }
  .navbar .navbar-nav {
    width: 100%;
  }
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <link rel="stylesheet" href="css/style.css" />
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
  <title>DropDown Menu</title>
</head>

<body>

  <nav class="navbar">
    <ul class="navbar-nav">
      <!-- Home -->
      <li class="nav-item h"><a href="#" class="item-link">Home</a>
      </li>
      <!-- Categories -->
      <li class="nav-item c">
        <a href="#" class="item-link">
          <i class="fa fa-angle-down" aria-hidden="true"></i> Investieren</a>
        <!-- Dropdown Menu -->
        <div id="drop-down">
          <a href="#" class="clinks"> <i class="fa fa-code" aria-hidden="true"></i> Web Development
          </a>
          <a href="#" class="clinks"> <i class="fa fa-android" aria-hidden="true"></i> Mobile Apps
          </a>
          <a href="#" class="clinks"> <i class="fa fa-adjust" aria-hidden="true"></i> UI / UX
          </a>
          <a href="#" class="clinks"> <i class="fa fa-database" aria-hidden="true"></i> Database
          </a>
          <a href="#" class="clinks"> <i class="fa fa-gamepad" aria-hidden="true"></i> Game Development
          </a>
        </div>
      </li>
      <!-- Prices -->
      <li class="nav-item p"><a href="#" class="item-link">Prices</a>
      </li>
      <!-- About -->
      <li class="nav-item a"><a href="#" class="item-link">About</a>
      </li>
    </ul>
  </nav>

</body>

</html>

>Solution :

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

The issue is you have the navbar set to top: 20%;. You need to set it the fixed position to top 0%:

.navbar {
   top: 0%;
   left: 0%;
   right: 0%;
}
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