I'm creating columns in my footer. It works well for Chrome and IE using:
column-count: 4;
break-inside: avoid-column;
I'm getting troubles with Firefox, where the property is crossed out:
What can I do?
Using page-break-inside: avoid
, I get something like this.
Some items move over his position, like "Item 9".
How it looks in Chrome:
For example:
#columnasFooter{
column-count: 3;
}
#columnasFooter li{
break-inside: avoid-column;
page-break-inside: avoid;
}
<ul id="columnasFooter">
<li>Title column 1
<ul>
<li>Item 1</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>
</li>
<li>Title column 2
<ul>
<li>Item 1</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>
<li>Item 9</li>
</ul>
</li>
<li>Title column 3
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
</ul>
</li>
</ul>
We can prevent column break within an element by using a CSS break-inside Property. The break-inside property in CSS is used to specify how the column breaks inside the element. Sometimes content of an element is stuck between the column. To prevent column break we should use the break-inside Property set to avoid.
The break-inside property specifies whether or not a page break, column break, or region break should occur inside the specified element. The break-inside property extends then CSS2 page-break-inside property. With break-inside , you can tell the browser to avoid breaks inside images, code snippets, tables, and listst.
Just applying overflow: hidden
on the li alongside breakInside: "avoid"
, fixed the issue for me on Firefox and it continued to work on Chrome
Works properly in Firefox with overflow: hidden
but this doesn't work in Chrome. So we should use @support
query to control overflowing. The below code works fine in Chrome and Firefox.
#columnasFooter {
column-count: 3;
}
#columnasFooter li {
break-inside: avoid-column;
page-break-inside: avoid;
overflow: hidden; /* fix for firefox */
}
@supports (break-inside: avoid-column) {
#columnasFooter li {
overflow: visible; /* for chrome */
}
}
<ul id="columnasFooter">
<li>Title column 1
<ul>
<li>Item 1</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>
</li>
<li>Title column 2
<ul>
<li>Item 1</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>
<li>Item 9</li>
</ul>
</li>
<li>Title column 3
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
</ul>
</li>
</ul>
I tried bugfix with page-break-inside: avoid
, but for me it didn't work fine with only this property and value on Firefox.
Then I used the following solution and, in my case, work well for Firefox, Chrome and Edge:
#columnasFooter {
column-count: 3;
}
#columnasFooter li {
/* for Chrome and Edge */
break-inside: avoid-column;
/* for Firefox */
display: inline-grid;
page-break-inside: avoid;
}
/* for Chrome and Edge */
@supports (break-inside: avoid-column) {
#columnasFooter li {
display: block;
}
}
As you can see, I used @supports rule to bugfix. Maybe, it could be useful to someone
Fire fox does not have support to break-inside
see here: https://developer.mozilla.org/en-US/docs/Web/CSS/break-inside
SO
Use page-break-inside:
for firefox:
column-count: 4;
break-inside: avoid-column;
page-break-inside:avoid;
See here about page-break-inside:avoid;
:
https://developer.mozilla.org/en-US/docs/Web/CSS/page-break-inside
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With