Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I render <li> side-by-side?

I'm looking to create a navigation menu with list items rendered in one line. How do I do this?

like image 485
Upcyclist Avatar asked May 27 '10 05:05

Upcyclist


People also ask

How do you display ul elements side by side?

You can set the li items to 'display: inline-block' or 'float: left'. Paulie_D is right. That will put all of your elements horizontally in a row.

How do I display list elements side by side in HTML?

Use CSS property to set the height and width of div and use display property to place div in side-by-side format. float:left; This property is used for those elements(div) that will float on left side. float:right; This property is used for those elements(div) that will float on right side.

How do you do side by side Li?

To force the li elements to be horizontal, we use the CSS float property. The float property is a positioning and formatting rule for the layout of content. We set the value of the float property to “left”, which floats all the li elements next to each other.


2 Answers

li {     display: inline; } 

EDIT: I now realize why I felt strange answering with display: inline: because I usually use float: left myself instead, which is anthony-arnold's answer (so to him goes my upvote!).

Anyway, while either method will cause your lis to display in one line, inline elements and floated elements do behave differently. Depending on how you've styled your layout, you may have to choose one or the other.

like image 174
BoltClock Avatar answered Oct 11 '22 17:10

BoltClock


You could also do this, for some situations:

 li {     float: left; } 
like image 36
Anthony Avatar answered Oct 11 '22 18:10

Anthony