Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"break-inside: avoid-column" doesn't work in Firefox

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:

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:

Google 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>
like image 794
eugneio dsjgfo Avatar asked Jun 04 '18 11:06

eugneio dsjgfo


People also ask

How do you prevent column breaks in an element?

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.

What are the CSS properties that are used to manage column breaks?

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.


4 Answers

Just applying overflow: hidden on the li alongside breakInside: "avoid", fixed the issue for me on Firefox and it continued to work on Chrome

like image 197
Shaun Pearce Avatar answered Oct 12 '22 11:10

Shaun Pearce


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>
like image 35
doğukan Avatar answered Oct 12 '22 11:10

doğukan


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

like image 42
Andrés Moreno Avatar answered Oct 12 '22 13:10

Andrés Moreno


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

like image 34
לבני מלכה Avatar answered Oct 12 '22 12:10

לבני מלכה