0

I have a top navbar on my test site that has space above with the body background color. I want to remove this so that the nav extends vertically to cover the viewport (that light blue color becomes the dark blue color of nav background color): enter image description here

body {
  background-color: #cce6ff;
  margin: 0px;
  border: 0px;
}
nav {
  font-family: 'Nunito Sans', sans-serif;
  font-size: 20px;
  background-color: #000033;
  height: 45px;
}
li {
  list-style-type: none;
  float: right;
  border-right: 2px solid white;
}
li:first-child {
  border-right: hidden;
}
li a {
  color: white;
  padding-left: 5px;
  padding-right: 5px;
}
<nav id="navbar">
  <ul>
    <li><a class="top-nav" id="home" href="#home">Home</a></li>
    <li><a class="top-nav" id="about-me" href="#about-me">About Me</a></li>
    <li><a class="top-nav" id="my-work" href="#my-work">My Work</a></li>
    <li><a class="top-nav" id="contact" href="#contact">Contact</a></li>
  </ul>
</nav>

I don't know where it's inheriting that space/padding from so I don't know how to troubleshoot it. I feel like I've tried everything.

Mister Jojo
  • 20,093
  • 6
  • 21
  • 40
calcodes26
  • 13
  • 5

4 Answers4

0

It's a default user agent style that your browser puts it in if you don't have a style set in a CSS reset for example. Set ul to have margin: 0 for this problem specifically.

body {
  background-color: #cce6ff;
  margin: 0px;
  border: 0px;
}
nav {
  font-family: 'Nunito Sans', sans-serif;
  font-size: 20px;
  background-color: #000033;
  height: 45px;
}
ul {
   margin: 0;
}
li {
  list-style-type: none;
  float: right;
  border-right: 2px solid white;
}
li:first-child {
  border-right: hidden;
}
li a {
  color: white;
  padding-left: 5px;
  padding-right: 5px;
}
<nav id="navbar">
  <ul>
    <li><a class="top-nav" id="home" href="#home">Home</a></li>
    <li><a class="top-nav" id="about-me" href="#about-me">About Me</a></li>
    <li><a class="top-nav" id="my-work" href="#my-work">My Work</a></li>
    <li><a class="top-nav" id="contact" href="#contact">Contact</a></li>
  </ul>
</nav>

StefanBob
  • 4,857
  • 2
  • 32
  • 38
0

Remove the nav tag and make the ul the only parent to the list elements and make the ul have a margin of 0.

body {
  background-color: #cce6ff;
  margin: 0px;
  border: 0px;
}
#navbar {
  font-family: 'Nunito Sans', sans-serif;
  font-size: 20px;
  background-color: #000033;
  height: 45px;
  margin-top: 0;
}
li {
  list-style-type: none;
  float: right;
  border-right: 2px solid white;
}
li:first-child {
  border-right: hidden;
}
li a {
  color: white;
  padding-left: 5px;
  padding-right: 5px;
}
<ul id="navbar">
    <li><a class="top-nav" id="home" href="#home">Home</a></li>
    <li><a class="top-nav" id="about-me" href="#about-me">About Me</a></li>
    <li><a class="top-nav" id="my-work" href="#my-work">My Work</a></li>
    <li><a class="top-nav" id="contact" href="#contact">Contact</a></li>
  </ul>
Hope this helps
Ameer
  • 1,980
  • 1
  • 12
  • 24
-1

Reset the margins and padding of all the elements. Also ensure you are not using some other CSS library

/*Reset the padding and margin for all the elements. Box sizing is optional*/
* {
  margin: 0px;
  padding: 0px;
  box-sizing: border-box;
}
Silverman42
  • 111
  • 7
-1

add this to your CSS:

ul {
margin-top= 0px;
}
NotTschuschl
  • 85
  • 1
  • 11