Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - <li> Items in Horizontal Menu have a Gap Between Them

Tags:

css

menu

The Issue

For some reason the left and right borders of the li items do not touch there is about a 4-5 px gap between them. I have no clue where it is coming from... I've spend a good amount of time monkeying around in Firebug with no luck...

The Markup

 <div id="menucontainer">      
      <ul id="menu">              
           <li><a href="google.com"></a></li>
           <li><a href="google.com"></a></li>
           <li><a href="google.com"></a></li>
      </ul>
 </div>

The CSS

#menucontainer
{
    display: block;
    float: left;
    width: 100%;
}

ul#menu
{
    display: block;
    padding: 5px 0px 5px 15px;
}

ul#menu li
{
    display: inline;
    padding: 3px;
    border-right: 1px solid #D8D6FF;
    border-left: 1px solid #D8D6FF;
    margin: 0 !important;
}

ul#menu li a
{
    padding: 3px;
    margin:0;
}

Other Info

I am using the 960 grid system CSS reset (which doesn't seem to change my issue w/ or w/o it). I need to get this working in IE 7+ and Firefox - Issue exists in IE8 and FF.

like image 300
Jason Avatar asked Oct 15 '10 13:10

Jason


People also ask

How do I reduce horizontal space between Li in HTML?

The spacing between list items in an orderedlist or itemizedlist element can be minimized by the document author by adding a spacing="compact" attribute to the list element. In HTML output, the list will get a compact="compact" attribute on the list start tag to reduce spacing in the browser.

How do you put space between Li tags in CSS?

Complete HTML/CSS Course 2022 We use CSS padding-left property, to create a space between bullets and the text. It is used to set the padding area on the left of an element.

How do you put a space between Li items?

Space can be added between each list item by setting a margin on the "LI". Margin can be set on the top, bottom or top and bottom of each list item. This version has a margin of ". 1em" on top and bottom of the list items.

Why is there a gap between 2 divs?

It is because of the white space in your HTML. Try removing the break between the two column-divs and it's gone, or try this solution: How to remove the space between inline-block elements?


2 Answers

You're using display: inline. That means that whitespace characters between each of those li elements are respected, and will be collapsed into a single space. If you need to, you can try using floats instead, or remove all whitespace between those elements.

 <ul id="menu">              
     <li><a href="http://example.com"></a>
     </li><li><a href="http://example.com"></a>
     </li><li><a href="http://example.com"></a></li>
 </ul>

would work, or if you're inclined to using floats,

#menu li {
    float: left;
}

instead of display: inline

like image 150
Yi Jiang Avatar answered Sep 28 '22 00:09

Yi Jiang


To follow on from Yi Jiang's solution:

<div id="menucontainer">      
  <ul id="menu">              
       <li><a href="google.com"></a></li><!--
    --><li><a href="google.com"></a></li><!--
    --><li><a href="google.com"></a></li>
  </ul>
</div>

ensures that you really don't have any white space. Floating left can cause problems in menus that have a rollover a:hover.

like image 29
satnhak Avatar answered Sep 27 '22 23:09

satnhak