35

I have a page with a structure similar to this:

<main>
    <section>
        <article></article>
        <aside></aside>
    </section>
</main>

In the CSS, I include the following:

main {
    display: flex;
    flex-direction: row;
}

The article is often many pages long.

When I print or print preview, I find that it only gives me the first page or so. After some experimenting, I have got this solution:

@media print {
    aside {
        display: none;
    }
    main {
        display: block;
    }
}

That is, by using display: block I can get all of the pages to print again. In this case, it’s OK, as I don’t want the aside to print, so I don’t need the flex behaviour, but that’s not always the case.

It seems to work well on Safari and Chrome. I am testing this on a Mac.

Why doesn’t this work on Firefox?

The actual page can be found at: https://www.internotes.net/articles/toggling-attributes. It’s still in its early stages.

1
  • Printing functionality in Firefox is being revised to some degree in 2020. Progress can be tracked here
    – phil294
    Commented May 11, 2020 at 17:44

2 Answers 2

26

Having looked into this for a bit now, I'm still not sure what about Firefox causes printing flex containers to be cut off. I found some extremely old bug reports on Bugzilla (eg. https://bugzilla.mozilla.org/show_bug.cgi?id=258397), but they had something to do with overflow properties on the body tag. Unfortunately, trying to adjust the overflow of body for this does nothing.

I even went to Bootstrap 4's page which uses layouts based on flexbox. Sure enough, attempting to print it on Firefox results in the same issue.

Finally, even display: inline-block has the same effect.

It seems to me that forcing display: block on print is what will ensure Firefox paginates correctly. Ideally, the layout you use for printing will be as simple as possible so that this doesn't become too much of a hindrance. Still, it's very surprising, at least to me.

Perhaps someone with more knowledge can chip in and inform whether this is a legitimate Firefox bug or just a part of their design philosophy.

5
  • 4
    I reported bug bugzilla.mozilla.org/show_bug.cgi?id=1414253 for this issue. Commented Nov 3, 2017 at 13:39
  • 1
    Having this exact same issue, and the problem is I need to change the order of children for the page to work, so it needs flex :( Commented Feb 7, 2018 at 22:33
  • 3
    Just saw this myself. Annoying as heck. Setting the display: flex element to display: block for @media print worked though. Thanks.
    – HartleySan
    Commented Nov 25, 2018 at 13:26
  • 3
    Even now, this bug does not seem to be fixed yet. bugzilla.mozilla.org/show_bug.cgi?id=939897
    – kaorukobo
    Commented Aug 1, 2019 at 4:31
  • 1
    I've run into this bug, too! Simple fix but sheesh it's been years.
    – jamesfacts
    Commented Oct 2, 2019 at 23:59
0

Bug not fixed yet: https://bugzilla.mozilla.org/show_bug.cgi?id=939897

Unfortunately seems like I'm hitting the same issue but because of CSS Grid. This is the site: https://cv.l3x.in

On macOs 10.14.6 it prints all right in Chrome and Safari, on Firefox 72.0 it's truncating the "Work experience" section at the first page break, skipping to the next item in the unsorted list.

The same content rendered without any display: grid prints correctly: https://cv.l3x.in/work

The same quick workaround works though, i.e. replacing display: grid with display: block

Not the answer you're looking for? Browse other questions tagged or ask your own question.