I'm trying to create a list of items that would look like this:
Main requirement is that the list should be flexible in a way that it's possible to add or remove list items without touching the code.
The best solution I found so far is to put all list items (including headers) into the <li>
tags and style them with one of the techniques presented in this A List Apart article:
<ul>
<li class="header">Drinks</li>
<li>Drink 1</li>
<li>Drink 2</li>
<li>Drink 3</li>
<li class="header">Meat</li>
<li>Meat 1</li>
<li>Meat 2</li>
<li>Meat 3</li>
<li>Meat 4</li>
<li>Meat 5</li>
<li>Meat 6</li>
etc.
</ul>
I was wondering if there are some better suggestions here on Stack Overflow.
Use the <ul> element for an unordered list and add <li> elements.
This is the simplest way to do it. CSS only. add width to the ul element. add display:inline-block and width of the new column (should be less than half of the ul width).
Probably the only way you can achieve this cleanly (without javascript) is using the column-count
CSS property. IE only supports it from 10+ though: http://caniuse.com/multicolumn
Here's a demo: http://jsbin.com/efiqov/2/
Also, headers should be headers, not list items.
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