How to style the UL list to a single line
CssCss Problem Overview
I want to render this list in a single line.
- List item1
- List item2
Should be shown as
*List item2 *List item2
What CSS style to use?
Css Solutions
Solution 1 - Css
ul li{
display: inline;
}
For more see the http://css.maxdesign.com.au/listamatic/">basic list options and http://css.maxdesign.com.au/listamatic/horizontal01.htm">a basic horizontal list at listamatic. (thanks to https://stackoverflow.com/users/65393/daniel-straight">Daniel Straight below for the links).
Also, as pointed out in the comments, you probably want styling on the ul and whatever elements go inside the li's and the li's themselves to get things to look nice.
Solution 2 - Css
In modern browsers you can do the following (CSS3 compliant)
ul
{
display:flex;
list-style:none;
}
<ul>
<li><a href="">Item1</a></li>
<li><a href="">Item2</a></li>
<li><a href="">Item3</a></li>
</ul>
Solution 3 - Css
HTML code:
<ul class="list">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
CSS code:
ul.list li{
width: auto;
float: left;
}
Solution 4 - Css
Try experimenting with something like this also:
> HTML
<ul class="inlineList">
<li>She</li>
<li>Needs</li>
<li>More Padding, Captain!</li>
</ul>
> CSS
.inlineList {
display: flex;
flex-direction: row;
/* Below sets up your display method: flex-start|flex-end|space-between|space-around */
justify-content: flex-start;
/* Below removes bullets and cleans white-space */
list-style: none;
padding: 0;
/* Bonus: forces no word-wrap */
white-space: nowrap;
}
/* Here, I got you started.
li {
padding-top: 50px;
padding-bottom: 50px;
padding-left: 50px;
padding-right: 50px;
}
*/
I made a codepen to illustrate: http://codepen.io/agm1984/pen/mOxaEM
Solution 5 - Css
in bootstrap use .list-inline
css class
<ul class="list-inline">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Ref: https://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_ref_txt_list-inline&stacked=h