gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

use "screen" with media queries on width so not to affect print view

Open Msmldavies opened this issue 2 years ago • 2 comments

Description

Some media queries in the block library don't use "screen" with max-width. This is causing problems with when using print view on sites.

For example, I have a set of columns which contain blocks with images in them. If I use this with print view it goes to flex-basis of 100 (and I can't override because of importance) which means that the image takes up full width of print page which is not what the user would expect.

@media (max-width:781px){ .wp-block-columns:not(.is-not-stacked-on-mobile)>.wp-block-column{ flex-basis:100% !important; } } From block-library/style.css

Step-by-step reproduction instructions

  1. build a page with block columns that would normally fit a number across width of a desktop page
  2. Add image somewhere within the block
  3. Do a print view and see result

Screenshots, screen recording, code snippet

@media (max-width:781px){ .wp-block-columns:not(.is-not-stacked-on-mobile)>.wp-block-column{ flex-basis:100% !important; } }

Environment info

No response

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

No

Msmldavies avatar Feb 21 '24 15:02 Msmldavies

I tested this on the latest setup:

  • WordPress: 6.8.1
  • Gutenberg: 20.9.0
  • Theme: TT5 1.2
  • OS: macOS
  • Browser: Chrome 137.0.0

When the print layout is set to landscape, the columns appear as expected, just like they do on the frontend in desktop view

Frontend View Print View
Image Image

However, if we want the portrait print layout to also match the desktop view, I noticed this only works when a custom width is set on the column (considering flex-basis: 100% is not applied in the print view). Otherwise, the columns wrap and take up full width.

From what I observed, when column widths aren't set explicitly, the columns behave as flex items with flex-grow: 1. Since no inline flex-basis is applied in that case, the column stretches to fill the available space and wraps, regardless of any default flex-basis values.

https://github.com/WordPress/gutenberg/blob/386df007aa1bf7bee05584d4cb1c45a32ece0d68/packages/block-library/src/columns/style.scss#L87-L88

@Msmldavies I'd really appreciate your thoughts on this. It’s possible I'm missing some context or details or there are environment specific factors at play. If you're able to share the environment where the issue occurred, that could help clarify things further.

BugReportOnWeb avatar Jun 24 '25 17:06 BugReportOnWeb

Raised a PR for this: https://github.com/WordPress/gutenberg/pull/86345

Not covered: the visible print fix is for Columns only. Gallery, RSS, Image and Navigation also use min-width queries and are not changed. I used print emulation, not a real print to PDF.

00kaku avatar Nov 05 '26 05:11 00kaku