Consider the following HTML:
- Number one
- Number two
&
The accepted answer is now two years old and things appear to have changed.
This article explains the use of the column-break-inside
property. I can't say how or why this differs from break-inside
, because only the latter appears to be documented in the W3 spec. However, the Chrome and Firefox support the following:
li {
-webkit-column-break-inside:avoid;
-moz-column-break-inside:avoid;
column-break-inside:avoid;
}
This works for me in 2015 :
li {
-webkit-column-break-inside: avoid;
/* Chrome, Safari, Opera */
page-break-inside: avoid;
/* Firefox */
break-inside: avoid;
/* IE 10+ */
}
.x {
-moz-column-count: 3;
column-count: 3;
width: 30em;
}
<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>
The following code works to prevent column breaks inside elements:
-webkit-column-break-inside: avoid;
-moz-column-break-inside: avoid;
-o-column-break-inside: avoid;
-ms-column-break-inside: avoid;
column-break-inside: avoid;
Try this:
-webkit-column-break-inside: avoid;
page-break-inside: avoid;
break-inside: avoid;
-webkit-column-break-inside: avoid-column;
page-break-inside: avoid-column;
break-inside: avoid-column;
...worked for me, might work for you.
<style>
ul li{display: table;}
</style>
works perfectly
Firefox now supports this:
page-break-inside: avoid;
This solves the problem of elements breaking across columns.