0

I've go an html from frontend developers. Part of the menu looks like the following:

<ul id="subNav">
    <li><a href="#">Menu item 1</a></li>
    <li><a href="#">Menu item 2</a></li>
</ul>

I had to add some programming tags, and to make code easier to read I've changed it to:

<ul id="subNav">
    <li>
        <a href="#">Menu item 1</a>
    </li>
    <li>
        <a href="#">Menu item 2</a>
    </li>
</ul>

After my change, the menu is broken. Space between elements are smaller. I have compared computed css and they look the same. Why is that? Why 'enter' between <li> and <a> break the layout?

Tested on Chrome.

EDIT: Fiddle: http://jsfiddle.net/bqyjL6rf/

kmb
  • 871
  • 5
  • 17
  • 34

2 Answers2

2

When you ran the tags together, you eliminate the white space inserted in inline elements. Breaking them apart, as in your second example, puts that white space back in and that is why your layout has changed.

Just as words you type into a paragraph, inline elements also have their white space between elements.

Rob
  • 14,746
  • 28
  • 47
  • 65
2

The spaces between these blocks are just like spaces between words. That's not to say the spec couldn't be updated to say that spaces between inline-block elements should be nothing, but I'm fairly certain that is a huge can of worms that is unlikely to ever happen.

To adjust that set display:inline-block instead of using display:inline

li {
    font-family: SlateProBk;
    font-size: .6rem;
    line-height: .6rem;
    text-transform: uppercase;
    opacity: 0.75;
    -webkit-opacity: 0.75; 
    margin: 0;
    padding: 0;
    display: inline-block;
    list-style-type: none;
    -webkit-font-smoothing: subpixel-antialiased;
}

Check this fiddle http://jsfiddle.net/bqyjL6rf/1/

rajesh
  • 1,475
  • 10
  • 23