I show list items in columns using flexbox. Items must be inserted into more columns after a certain height, columns must be centered horizontally, and list items in each column must be justified. I use max-height
to limit the height of the list, flex-flow: column wrap
to create wrapping columns, and align-content: center
to center the columns.
I understand that a multi-column solution may be more obvious, but I do not want to define column-width
or column-count
, so I chose the flexbox solution.
Problem
Columns are only horizontally positioned when items are wrapped across multiple columns. If there is only one column, then the column is not centered. I see this behavior in Chrome 63 on both Windows 10 Home and MacOS Sierra. In Firefox, it looks as I expected (screenshots below).
Am I missing something?
How can I make a column always be horizontally centered, cross browser?
.filter_drop {
display: flex;
flex-flow: column wrap;
align-content: center;
list-style: none;
margin: 0;
padding: 0;
max-height: 7em;
border-bottom: 1px solid black;
}
.filter_drop li {
margin: 0 1em 0 0;
line-height: 1.2;
}
<ul class="filter_drop">
<li>One</li>
<li>Two </li>
<li>Three</li>
<li>Four</li>
<li>Five</li>
<li>Six</li>
<li>Seven</li>
<li>Eight </li>
<li>Nine</li>
<li>Ten</li>
<li>Eleven</li>
<li>Twelve</li>
</ul>
<ul class="filter_drop">
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
<li>Five</li>
<li>Six</li>
<li>Seven</li>
</ul>
<ul class="filter_drop">
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
</ul>
<ul class="filter_drop">
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
Run codeHide resultView in JSFiddle
Chrome 63:

Firefox 57:

source
share