Consider the following HTML:
<div class='x'>
<ul>
<li>Number one</li>
<li>Number two</li>
<li>Number three</li>
<li>Number four is a bit longer</li>
<li>Number five</li>
</ul>
</div>
and the following CSS:
.x {
-moz-column-count: 3;
column-count: 3;
width: 30em;
}
As it stands, Firefox currently renders this similarly to the following:
• Number one • Number three bit longer
• Number two • Number four is a • Number five
Notice that the fourth item was split between the second and third column. How do I prevent that?
The desired rendering might look something more like:
• Number one • Number four is a
• Number two bit longer
• Number three • Number five
or
• Number one • Number three • Number five
• Number two • Number four is a
bit longer
Edit: The width is only specified to demonstrate the unwanted rendering. In the real case, of course there is no fixed width.
A possible workaround for Firefox is to set the CSS property "display" of the element you don't want to have a break inside to "table". I don't know if it works for the LI tag (you'll probably lose the list -item-style), but it works for the P tag.
As of October 2014, break-inside still seems to be buggy in Firefox and IE 10-11. However, adding overflow: hidden to the element, along with the break-inside: avoid, seems to make it work in Firefox and IE 10-11. I am currently using:
Firefox now supports this:
This solves the problem of elements breaking across columns.
This answer might only apply to certain circumstances; If you set a height to your elements, this will be obeyed by the column styling. There-by keeping anything that is contained within that height to a row.
I had a list, like the op, but it contained two elements, items and buttons to act upon those items. I treated it like a table
<ul> - table
,<li> - table-row
,<div> - table-cell
put the UL in a 4 column layout. The columns were sometimes being split between the item and it's buttons. The trick I used was to give the Div elements a line height to cover the buttons.set following to the style of the element that you don't want to break:
I faced same issue while using card-columns
i fixed it using