I'm using css columns (not a table) to create a list that spans across 3 columns, like so:
HTML
<ul>
<li>- Item 1 - this is the item's name here.</li>
<li>- Item 2</li>
<li>- Item 3</li>
<li>- Item 4</li>
<li>- Item 5</li>
<li>- Item 6</li>
<li>- Item 7</li>
<li>- Item 8</li>
</ul>
CSS
ul {
column-count: 3;
max-width: 40rem;
}
How it displays
However, all columns are of equal width and this causes a difference in spacing between them. How can I adjust css columns to get something like this, where each column's width depends on the content?
What I'm trying to achieve:
Thanks!
EDIT: I should mention that I need to use CSS columns because these list of items are being generated dynamically through a CMS, so would like to find a purely CSS solution if possible to avoid having to introduce Javascript to manipulate the DOM. Thank you.
flex-growth
andflex-shrink
styles – Hamlen