I'm looking to create a navigation menu with list items rendered in one line. How do I do this?
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.
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.
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.
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 li
s 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.
You could also do this, for some situations:
li { float: left; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With