I have a simple HTML list:
<ul>
<li>First Item</li>
<li>Second Item</li>
<li>Third Item</li>
</ul>
I want to display the list with the following features:
- Items in a row.
- List would have a maximum width, after which items are expected to break to the next line.
- Items should only break on beginning / spaces (not mid-word).
- Lines should contain the most text possible before breaking.
Desired outcome:
[ maximum width ]
First Item * Second
Item * Third Item
Failed attempts:
#1 (word breaks)
[ maximum width ]
First Item * Second I
tem * Third Item
#2 (item doesn't break properly)
[ maximum width ]
First Item * Second Item
* Third Item
#3 (line breaks "prematurely")
[ maximum width ]
First
Item * Second Item *
Third Item
Update:
A simple li {display: inline;}
won't work if the HTML is not indented / spaced (some frameworks -- say, GatsbyJS -- automatically "squeeze" the HTML):
<ul><li>First Item</li><li>Second Item</li><li>Third Item</li></ul>