1

The column-fill:auto property works by first populating one full column before going to the next.

.two-column {
  column-count: 2;
  column-fill: auto;
}

Chrome does this only correctly on screen, but not when printing and having to deal with page breaks:

A C
B D
---- page break
E G
F H
---- page break
I J  <-- two columns

However, the remaining part of the list that breaks into the last page, the layout reverts back to a "balanced"-style. At least, Chrome does, FireFox, displays it correctly:

A C
B D
---- page break
E G
F H
---- page break
I
J

Is this a (known) Chrome bug? Is there any workaround for it?

Example: https://codepen.io/Stu42/pen/PoqYYWo

Update: As pointed out by Juan Marco, this is likely a Chrome bug. As discussed here: https://github.com/w3c/csswg-drafts/issues/4036. Any clear reference to a official bug or status, or better, a workaround would count as an answer, I think.

svenema
  • 1,766
  • 2
  • 23
  • 45
  • Have a [mcve] you can add to the question in order to demonstrate this? – TylerH Feb 03 '20 at 21:48
  • +2,5yrs: Looks like people are working on implementing this in something called "css-multicol-1" https://github.com/w3c/csswg-drafts/projects/4#card-22807684 – svenema Jun 12 '22 at 20:51
  • Multicolumn layout is a [module](https://www.w3.org/TR/css-multicol-1/) that has been CR since last year, and that all major browsers have largely supported for many years already. – TylerH Jun 13 '22 at 18:27

2 Answers2

1

I know this is old but I just ran into this issue. I was able to fix it by creating a child div within the containing element that sets up the grid, and then setting break-inside to avoid.

E.g., from your example, something like this:

 <div class="two-column">
    <div style="break-inside: avoid;">
      <p>A</p>
      <p>B</p>
      <p>C</p>
      <p>D</p>
      <p>E</p>
      <p>F</p>
    </div>
  </div>

This causes the last page to not break the two paragraphs apart so you end up with this structure:

A C
B D
---- page break
E
F

Hope that helps someone.

markquezada
  • 8,444
  • 6
  • 45
  • 52
  • Works for me, But this adding extra blank page while generating pdf – Suraj Parise Oct 19 '22 at 10:23
  • 1
    @SurajParise I also use this for generating a PDF and didn't have that problem. Most likely there is extra margin or padding at the end of your document that is causing another page break. (I ran into a similar issue and realized I had a margin-bottom declaration that was causing the extra page.) – markquezada Nov 04 '22 at 00:28
0

For column-fill MDN says:

Note that there are some interoperability issues and bugs with column-fill across browsers, due to unresolved issues in the specification.

Whenever you plan to use a feature that's experimental or not well supported check caniuse for info. Then use Autoprefixer to get the necessary vendor prefixes (if any).

For example, for the style rule:

.two-column {
    column-count: 2;
    column-gap: 1cm;
    column-fill: auto;
    background-color: #faa;
}

Autoprefixer generated this:

.two-column {
    -webkit-column-count: 2;
       -moz-column-count: 2;
            column-count: 2;
    -webkit-column-gap: 1cm;
       -moz-column-gap: 1cm;
            column-gap: 1cm;
    -webkit-column-fill: auto;
       -moz-column-fill: auto;
            column-fill: auto;
    background-color: #faa;
}
Juan Marco
  • 3,081
  • 2
  • 28
  • 32
  • that is nice, wasn't aware of any of that... however, very unfortunately, this doesn't "fix" Chrome. Updated my example with the generated auto prefixes. – svenema Feb 04 '20 at 17:33
  • Glad that was informative. When I researched `column-fill`, I found an [open issue regarding the way it behaves in paginated and continuous contexts](https://github.com/w3c/csswg-drafts/issues/4036). You might need to find an alternative until it's resolved. – Juan Marco Feb 04 '20 at 18:18
  • Ok, so looks to be a Chrome bug.. too bad. – svenema Feb 05 '20 at 12:19