Remove white space from the sides and top of my navbar

12,803

Solution 1

Is this what you're looking for?

Link to JSFiddle

If so, in your CSS. Add this

body {
   margin: 0px;
}

Solution 2

None of the solutions I've were working for me, but I found one that did. In my CSS:

.navbar{
  margin-left: -15px;
  margin-right: -15px;
}

It seemed like mine had about 15 pixels of margin on just that I couldn't get away by setting the margin to 0.

Share:
12,803
The Killj0y
Author by

The Killj0y

Updated on June 05, 2022

Comments

  • The Killj0y
    The Killj0y almost 2 years

    I have looked around for many solutions and I am currently redoing the code of a website I own as I had all of my CSS individually laid out on each HTML page. Eventually I had too many pages to handle, and I decided to make a stylesheet to clean it all up but my EVERYTHING was a mess. Indentation, comments, etc...

    Currently, I am working on my Navigation Bar on the Website, but for some reason which I can't figure out (I've tried many things) the bar is positioned exactly in the middle which leaves a small amount of white space at the top, left and right of the bar. Here is the HTML:

    ul { /* unordered list properties */
      list-style-type: none; /*takes out bullet points */
      margin: 0; /* scaling */
      padding: 0; /* scaling */
      overflow: hidden; /* clipping rules: https://www.w3schools.com/cssref/pr_pos_overflow.asp */
      background-color: #0c1f2e; /* colour */
    }
    li { /* list item properties */
      float: left; /* move item to the left */
      font-size: 14px; /* set the font size to 14 pixels */
    }
    li a { /* vertical style */
      display: block; /* display style */
      color: #ffffff; /* text colour */
      text-align: center; /* centres the text */
      padding: 19px; /* vertical padding */
      text-decoration: none; /* remove any text effects */
      font-family: 'Dosis', sans-serif; /* change the font to selected font: Dosis */
    }
    li a:hover { /* vertical style items when hovered upon by cursor properties */
      background-color: #639ddf; /* set the background colour */
      font-size: 20px; /*set the font size to 20 pixels */
    }
        <nav> <!-- begin navigation element -->
          <div id="menu"> <!-- create and start new element with the id: menu -->
            <ul> <!-- begin unordered list -->
              <li><a href="index.html">Home</a></li><!-- list items -->
              <li><a href="WebsiteCompetitions.html">Competitions</a></li>
              <li><a href="WebsiteBuilds.html">Builds</a></li>
              <li><a href="WebsiteImages.html">Images</a></li>
              <li><a href="WebsiteVideos.html">Videos</a></li>
              <li><a href="WebsiteComm.html">Fight Club</a></li>
              <li><a href="WebsiteArticles.html">Articles</a></li>
              <li><a href="/mybb">Forums</a></li>
              <li><a href="WebsiteTools.html">Tools</a></li>
              <li><a href="WebsiteNews.html">News</a></li>
              <li><a href="WebsiteOffers.html">Shop</a></li>
              <li><a href="cooperators.html">Allies</a></li>
              <li><a href="WebsiteMore.html">More</a></li>
            </ul> <!-- end the unordered list -->
          </div> <!-- end the 'menu' element -->
        </nav> <!-- end navigation element -->

    Thanks all in advance, I hope I have provided enough info and please don't be too harsh with my over-commenting or anything just keep those opinions to yourself. As for my question structure and code, please correct me on anything I've done wrong and point out how I can fix. Thank you very much for taking your time to read this,

  • tao
    tao over 6 years
    It's not the browser, it's Stack Overflow snippet. Most likely, this has to do with padding on <body>.
  • pavger
    pavger over 6 years
    No it's not. I created a new html page with the code from above on my computer and opened it up in Chrome. I inspected it and the user agent stylesheet was adding margin: 8px; to the body. Most sites include css resets that remove this margin to the body.
  • ddr45
    ddr45 about 6 years
    Great, glad to hear!
  • Caleb Bassham
    Caleb Bassham almost 3 years
    This is not exactly the idomatic way deal with margin.