use "screen" with media queries on width so not to affect print view
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
- build a page with block columns that would normally fit a number across width of a desktop page
- Add image somewhere within the block
- 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
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 |
|---|---|
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.
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.