zebravis
zebravis

Reputation: 3

Remove whitespace from my navigation bar

This is my code (im a total noob in html) this code gives me whitespace on top and on the left of my navigation... do you guys have any idea of what im doing wrong?

    div.nav {
  background-color: black;
  color: white;
  font-size: 20px;
  font-weight: bold;
  position: fixed;
  width: 100%;
  text-align: center;
}
ul {

}
li {
  display: inline-block;
  list-style: none;
}
li a {
  padding: 15px;
  color: white;
}


<div class="nav">
  <ul>
    <li><a href="index.html">Home</a></li>
    <li><a href="watisdb.html">Wat is D&B</a></li>
    <li><a href="dbnederland.html">D&B in Nederland</a></li>
  </ul>
</div>

Added html

Upvotes: 0

Views: 109

Answers (2)

Alexander Gorbatovsky
Alexander Gorbatovsky

Reputation: 54

this is CSS. Add this

body{
   padding: 0;
   margin: 0;
 }

body{
   padding: 0;
   margin: 0;
   
   background-color: #e8e4e5;
 }
 div.nav {
  background-color: black;
  color: white;
  font-size: 20px;
  font-weight: bold;
  position: fixed;
  width: 100%;
  text-align: center;
}
ul {

}
li {
  display: inline-block;
  list-style: none;
}
li a {
  padding: 15px;
  color: white;
}
<div class="nav">
  <ul>
    <li><a href="index.html">Home</a></li>
    <li><a href="watisdb.html">Wat is D&B</a></li>
    <li><a href="dbnederland.html">D&B in Nederland</a></li>
  </ul>
</div>

But you can set to nav div position fixed: it will help when you get scroll in content, but nav div all time will in top.

 body{
   padding: 0;
   margin: 0;
 }
 .content{
   margin-top: 60px;
   height: 150vh;
   background-color: #d2d29d;
 }
 div.nav {
  position: fixed;
  height: 60px;
  background-color: black;
  color: white;
  font-size: 20px;
  font-weight: bold;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  text-align: center;
}
ul {

}
li {
  display: inline-block;
  list-style: none;
}
li a {
  padding: 15px;
  color: white;
}
<div class="nav">
  <ul>
    <li><a href="index.html">Home</a></li>
    <li><a href="watisdb.html">Wat is D&B</a></li>
    <li><a href="dbnederland.html">D&B in Nederland</a></li>
  </ul>
</div>
<div class="content">
  Some text
</div>

Upvotes: 1

Mike Donkers
Mike Donkers

Reputation: 3699

Since you're using position:fixed; you can change you css to the following, which will force the navbar to be in the top-left corner of your page

div.nav {
    background-color: black;
    color: white;
    font-size: 20px;
    font-weight: bold;
    position: fixed;
    top:0; //<================= Add this
    left:0; //<================= And add this
    width: 100%;
    text-align: center;
}

Ofcourse, there's many more ways. The above CSS will result in your whitespace being removed

    div.nav {
  background-color: black;
  color: white;
  font-size: 20px;
  font-weight: bold;
  position: fixed;
  top:0; //<================= Add this
  left:0; //<================= And add this
  width: 100%;
  text-align: center;
}
ul {

}
li {
  display: inline-block;
  list-style: none;
}
li a {
  padding: 15px;
  color: white;
}
<div class="nav">
  <ul>
    <li><a href="index.html">Home</a></li>
    <li><a href="watisdb.html">Wat is D&B</a></li>
    <li><a href="dbnederland.html">D&B in Nederland</a></li>
  </ul>
</div>

Hope this helps!

Upvotes: 0

Related Questions