0
<div id="menuNav">
    <ul id="menuNav-ul">
        <li><a href="#">Home</a></li>
        <li><a href="#">Page 1</a></li>
        <li><a href="#">Page 2</a></li>
    </ul>
</div>

I have a JSFiddle that I've made here:

http://jsfiddle.net/agzF5/

If you hover over the menu items that aren't the first of type you'll notice there is some strange margin appearing after where the border would be if it were set, I was wondering as to how I can remove that?

Matt

Irfan TahirKheli
  • 3,582
  • 1
  • 19
  • 34
Matthew
  • 302
  • 4
  • 18

5 Answers5

0

add

html, body{margin:0;} 

to the top, body alone should probably work as well..

Tsasken
  • 691
  • 5
  • 16
0

JSFiddle here

You had your list items as display:inline-block;

I've floated them left, added display:block; and changed some properties on the wrapping element. so it still contains the floated elements, see below.

#menuNav-ul {
    background: lightgrey repeat-x;
    list-style-type: none;
    padding: 0;
    margin: 0;
    border-bottom: 2px solid darkgrey;
    display:block;
    overflow:hidden;
}

#menuNav-ul li {
    display: block;
    border-right: 1px solid #bfbfbf;    
    margin: 0px;
    padding: 0px;
    float:left;
}
0

You're setting your LI elements to be display:inline-block which means they will have a inline whitespace space between them (usually ~4px).

3 solutions:

1. LIVE DEMO

add font-size:0; to the UL
reset the font size to px for the LI elements

2. don't add display:inline-block; but float:left; your LI elements

3. (not recommended) add a -4px margin-left to your LI elements


P.S: an additional suggestion is not to style (colors, borders etc) you LI elements. Treat them like simple positioned containers for your styled <a> elements.

Community
  • 1
  • 1
Roko C. Buljan
  • 164,703
  • 32
  • 260
  • 278
0

Others have answered with good solutions.

I wanted to leave this here in case it helps someone though.

The reason for this is that there is whitespace in your markup (totally fine), which inline-block renders as spaces.

If you are working with inline-block elements, you can to set the font-size of the parent to 0, then explicitly set the font-size of the child elements as a workaround for this.

mattbeck
  • 135
  • 7
0

Well the simple solution is to add comment between your li items:

<div id="menuNav">
    <ul id="menuNav-ul">
        <li><a href="#">Home</a></li><!--
        --><li><a href="#">Page 1</a></li><!--
        --><li><a href="#">Page 2</a></li>
    </ul>
</div>

Check it in action: http://jsfiddle.net/agzF5/7/

Irfan TahirKheli
  • 3,582
  • 1
  • 19
  • 34