English 中文(简体)
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>
<li class="item2"> ... </li>
...

However, if I add a 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.





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签