views:

71

answers:

3

Hey, Is there a way to get browsers to ignore line breaks in the source?

<div id="navbar">
    <div id="navbar-container">
        <ul>
            <li>HOME</li>
            <li>TUTORIALS</li>
            <li>BLOG</li>
            <li>FORUMS</li>
            <li>LINKS</li>
            <li>&nbsp;</li>
        </ul>
    </div>
</div>

#navbar {
    background:#FFF;
    width:940px;
    margin:auto;
    border-radius: 10px 10px;
    -webkit-box-shadow: 5px 5px 10px #888;
}
#navbar-container {
    margin:auto;
}
#navbar-container ul {
    list-style:none;
    text-align:center;
    display:block;
    width:auto;
    padding:0;
    margin:0;
}
#navbar-container li{
    list-style:none;
    border-left:3px solid black;
    display:inline-block;
    font-family:"Arial", sans-serif;
    font-size:2em;
    padding:0 7px 0 10px;
    margin:0;
    white-space:nowrap;
}
#navbar-container li:hover{
    color:#FFF;
    background:#000;
    border-left:3px solid black;
    display:inline-block;
    font-family:"Arial", sans-serif;
    font-size:2em;
    margin:0;
    padding:0 7px 0 10px;
}

It's placing a small space between each LI, I've set it up so then line up horizontally, i could just remove the line breaks in the source, but id prefer not to.

A: 

All browsers should totally ignore whitespace. Is there a particular browser giving you trouble?

Try:

li { margin: 0; padding: 0 }
tandu
it's on all of them, ive already set the margin to 0 and the padding on each side is set to give the text some space, ill update the question with CSS
Diesal11
They don't 'ignore' white-space, they simply collapse it down to a single space. Which is expressed as a break between the `li`s when displayed in-line. If they're floated, then it's ignored.
David Thomas
Then maybe a better approach would be to somehow get them to treat it as a space rather than a br... I know that would have made my life a lot easier a few times if I could have figured out how.
RonLugge
+2  A: 

You can float them (either left or right), or you can comment-out the spaces:

<ul>
  <li>...</li><!--
  --><li>...</li>
</ul>

Or simply leave the tags open 'til the next line.

<ul>
  <li>...</li
  ><li>...</li
  ><li>...</li>
</ul>
David Thomas
Agh, beat me to the open tag solution. I haven't ever seen a problem in any browser besides IE.
jball
the leaving the tags open solution worked, ill give you the answer as you gave the solution first. thanks!
Diesal11
It's one of my favourites =)
David Thomas
messing with the mark up is WRONG - make sure you use the 'float' method!
Adrian
+1  A: 

IE seems to do that as a hold-over from the days when list items did not have closing tags. A common way around that is to put the closing > on the next line, i.e.

<ul>
        <li>HOME</li
        ><li>TUTORIALS</li
        ><li>BLOG</li
        >etc...
jball