Having line breaks between <li> s

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

Elements should be next to each other.

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

 <li class="item1 first"> ... </li> <li class="item2"> ... </li> ... 

However, if I add \n after each item, the menu items have a gap between them. I understand that this is the intended behavior, but is there a way to turn it off with smart β€œwhite space” or something else?

Edit: I cannot use float, it is in CMS with the ability to center list items.

+4
source share
4 answers

You can avoid rendering problems, but maintain the code as follows:

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

It removes spaces, but it's still easy to edit elements in a text editor if your CMS is not confused with the markup you enter!

+5
source

Do you have the ability to edit CSS? If so, you can try adjusting the padding / fields to the <li> element. He seems to have a lot of reading effort.

Depending on which browser you use, you may get HTML Tidy http://users.skynet.be/mgueury/mozilla/ , which gives you the option to remove your source, which may be useful enough for debugging

+1
source

CSS + float is your friend.

0
source

HTML is space-independent, so adding line breaks should not have any effect. However, some browser rendering engines do not quite understand this.

What you probably want to do is add

float: left;

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

0
source

All Articles