6

There seems to be a bug in calculation of multi column css property, present in all browsers I have checked in (latest Chrome, IE11 and Firefox). If you have 9 items in your list, and try to split it in 4 columns, the last column is always empty.

Are there any workarounds, something that will split it 3/2/2/2? Thanks in advance.

ul {
  -moz-column-count: 4;
  -webkit-column-count: 4;
  column-count: 4;
  background-color: gray;
}
li {
  background-color: tomato;
}
<ul>
  <li>item</li>
  <li>item</li>
  <li>item</li>
  <li>item</li>
  <li>item</li>
  <li>item</li>
  <li>item</li>
  <li>item</li>
  <li>item</li>
</ul>

4
  • The column number exactly is 4 but minimum item per column is 3 items so if you add one more li, it will show in the last column Commented Nov 11, 2016 at 9:57
  • 9 % 4 != 0. Basically, why should that work? What did you expect to happen? Commented Nov 11, 2016 at 9:59
  • its not about calculation its about the column height when one column have 3 items others also create space for an other Commented Nov 11, 2016 at 10:00
  • yes, this problem is not about the ul height even set its height may effect to the number of column, but it's not solve the real problem Commented Nov 11, 2016 at 10:05

3 Answers 3

1

http://caniuse.com/#feat=multicolumn

It looks like the column-* has alot of issues with different browsers. In your example if you were to add 1 more li element, then you can see it will fill itself in on the 4th column. My guess is its a divisibility issue.

Sign up to request clarification or add additional context in comments.

Comments

1

It is working in same way that it supposed to work, there is enough space in 3 columns for 9 items that's why its not going into 4th, reduce height and it will be divide in more columns. or add more li that will go in 4th column

ul {
  -moz-column-count: 4;
  -webkit-column-count: 4;
  column-count: 4;
  background-color: gray;
  height:50px;
}
li {
  background-color: tomato;
}
<ul>
  <li>item</li>
  <li>item</li>
  <li>item</li>
  <li>item</li>
  <li>item</li>
  <li>item</li>
  <li>item</li>
  <li>item</li>
  <li>item</li>
</ul>

5 Comments

The problem is that i need a dynamic height, for example if more elements will be added down the line.
Then there shouldn't be any problem. Column will work fine.
@downvoter! Please explain your downvote, so I can improve answer.
if i will set the height to a fixed number, and add more list items afterwards, they will overflow the ul and will not be visible
Use auto fill for columns, that will be filled according to element height.
-1

Use this:

.keeptogether{
display:inline-block;
width:100%
}

ul {
  -moz-column-count: 4;
  -webkit-column-count: 4;
  column-count: 4;
  background-color: gray;
}
li {
  background-color: tomato;
}
.keeptogether {
  display: inline-block;
  width: 100%
}
<ul>
<div class="keeptogether">
  <li>item</li>
  <li>item</li>
  <li>item</li>
</div>
<div class="keeptogether">
  <li>item</li>
  <li>item</li>
</div>
<div class="keeptogether">
  <li>item</li>
  <li>item</li>
</div>
<div class="keeptogether">
  <li>item</li>
  <li>item</li>
</div>
</ul>

1 Comment

You cannot put a div between ul and li elements, that is invalid html.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.