Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove white space above nav bar

Tags:

html

css

How do I remove the white space above this navbar that I created?

http://gyazo.com/b41271cad8d41c08c52ff26b1f1cab9e

I have search StackOveflow for this answer, but can't find one that seems to fix my issue. I have set html, body padding/margin to 0 as well as reset all other elements. Does anyone have any advice?

<nav id="header">
  <div class="home-header">
    <a href="#"><h1> testing this </h1></a>
  </div>
</nav>

Here's the CSS

#header {
  position: relative;
  margin: 0 auto 0;
  padding-top: 0px;
  background-color: $main-color;
}
like image 531
kevin Avatar asked Jun 06 '14 19:06

kevin


People also ask

How do I get rid of the white space in my navigation bar?

Setting margin on your nav to 0px and setting body padding to 0px; should works.

Why is there space above my nav bar?

This is caused by a css style. By the way already a big thank you for your answers, really appreciate it! The larger breakpoint has the margin.

How do I fix the top navigation bar in CSS?

Step 2) Add CSS: To create a fixed top menu, use position:fixed and top:0 . Note that the fixed menu will overlay your other content. To fix this, add a margin-top (to the content) that is equal or larger than the height of your menu.


1 Answers

Live demo

The space at the top is create by the h1 because of its default margin. To fix this:

#header h1{
    margin:0px;
}

PS: I assume that you removed the margin for the body tag. If not here's how you remove it:

body{
    margin:0;
}
like image 137
CMPS Avatar answered Oct 16 '22 14:10

CMPS