开发者

Having line breaks between <li>s

I have a horizontal menu consisting of <li> elements with display: inline.

The elements are supposed to be next to each other seamlessly.

In the source code, I would like to have each li on one line for easier debugging:

<li class="item1 first"> ... </li&开发者_高级运维gt;
<li class="item2"> ... </li>
...

However, if I add a \n after each element, the menu items have a gap between each other. I gather this is the intended behaviour, but is there any way to turn it off using a clever "white-space" setting or something?

Edit: I can't use float, this is in a CMS with the option to center the list items.


You can avoid the rendering issues but keep the code maintainable like this:

<ul
  ><li>item 1</li
  ><li>item 2</li
  ><li>item 3</li
></ul>

It removes the whitespace but it's still easy to edit the items in a text editor, provided your CMS doesn't mess with the markup you enter!


Do you have the ability to edit the CSS? If so, you could try adjusting the padding/margins on the <li> element. It does seem to be a lot of effort of readability.

Depending on what browser you are using you can get the HTML Tidy http://users.skynet.be/mgueury/mozilla/, which gives you the option to Tidy up your source, which might be useful enough for debugging


CSS+float is your friend.


HTML is whitespace independent - so adding line breaks should have no effect. Some browser's rendering engines don't quite get this right however.

What you probably want to do is add

float: left;

to your li tags to get them next to each other.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜