Nikita Karpov
Nikita Karpov

Reputation: 3

HTML nav bar whitespace issue

I'm creating an HTML nav bar for the first time and I'm having white space issue, I fixed it only sideways(left, right) but there is still space on the top of the nav bar. Pls help to fill it.

Image of the problem - Image

This is my CSS and HTML. Run the code and open in full mode.

li.na-li {
  float: left;
  text-align: center;
  font-size: 20px;
    }

    

li.na-li a.na-a {
        display:block;
        text-decoration: none;
        color:white;
        padding: 15px;
        
    
    }
li a:hover{background-color: #00F003}   
    
ul.na-ul {
        background-color:#000000;
        position: fixed;
        top: 0;
        width: 100%;
        list-style-type: none;
        
    }   
.navbar {
        background-color: #073A00;
        width: 0%;
    }       
    
body {
width: 100%;
height: 100%;
padding: 0px;
margin: 0px;
overflow-x: hidden;
}

    
    
   
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

    
<body>

    <div class="navbar">
<ul class="na-ul">
    <li class="na-li"><a class="na-a" href="#home">Home</a></li>
    <li class="na-li"><a class="na-a" href="Services"> Services</a></li>
    <li class="na-li"><a class="na-a" href="Contact">Contact</a></li>
    <li class="na-li"><a class="na-a" href="Help">Help</a></li>
    </ul>   
</div>  
    
    
</body>
</html>

Upvotes: 0

Views: 143

Answers (4)

Sayedur Rahman
Sayedur Rahman

Reputation: 171

The element has browser inherent padding & margin by default. In your case, Use

ul.na-ul {
    margin: 0; /* To remove default margin */ 
    padding: 0; /* To remove default padding */
}

or a CSS browser reset ( https://cssreset.com/ ) to deal with this.

Upvotes: 1

Ajeet Eppakayala
Ajeet Eppakayala

Reputation: 1415

ul.na-ul { margin: 0 } or ul.na-ul { margin-top: 0 } if you want space at bottom of navbar.

li.na-li {
  float: left;
  text-align: center;
  font-size: 20px;
}

li.na-li a.na-a {
  display: block;
  text-decoration: none;
  color: white;
  padding: 15px;
}

li a:hover {
  background-color: #00F003
}

ul.na-ul {
  background-color: #000000;
  position: fixed;
  top: 0;
  width: 100%;
  list-style-type: none;
  margin: 0;
}

.navbar {
  background-color: #073A00;
  width: 0%;
}

body {
  width: 100%;
  height: 100%;
  padding: 0px;
  margin: 0px;
  overflow-x: hidden;
}
<!doctype html>
<html>

<head>
  <meta charset="utf-8">
  <title>Untitled Document</title>
</head>


<body>

  <div class="navbar">
    <ul class="na-ul">
      <li class="na-li"><a class="na-a" href="#home">Home</a></li>
      <li class="na-li"><a class="na-a" href="Services"> Services</a></li>
      <li class="na-li"><a class="na-a" href="Contact">Contact</a></li>
      <li class="na-li"><a class="na-a" href="Help">Help</a></li>
    </ul>
  </div>


</body>

</html>

Upvotes: 1

Nate Levin
Nate Levin

Reputation: 1118

Try adding

body {
    margin: 0 0;
}
ul.na-ul {
    margin-top: 0;
}

See the answer below as to why there is a margin by default. How wide is the default `<body>` margin?

Upvotes: 0

Rod911
Rod911

Reputation: 860

You need to get rid of the default styling of uls.

Add margin-top: 0; in the css under ul.na-ul.

Upvotes: 0

Related Questions