Media queries in custom CSS for Gutenberg blocks are not being applied correctly.
The issue involves media queries in custom CSS for Gutenberg blocks not being applied correctly, particularly after updating to Gutenberg 16.8.0 and later versions. The problem appears to be related to how media queries are processed or applied within the block styles. Reproduction steps are provided, but the root cause is not immediately clear, requiring investigation into CSS handling in Gutenberg.
I have a query pagination that looks like this:
I opted to hide the pagination numbers with a media query applied as custom CSS in the
core/query-pagination-numbers block style.
@media screen and (max-width: 599px) {
& .page-numbers {
display: none;
}
}
But after updating gutenberg from 16.7.1 to 16.8.0 (and 16.8.1 now) I noted that my query pagination numbers were also hidden on higher resolutions with a display: none applied.
This is in theme.json in styles.blocks.core/query-pagination-numbers.css
"css": "& .page-numbers.current { padding: .5rem .7rem; border-radius: .25rem; color: var(--wp--preset--color--query-pagination-numbers-current-contrast); background-color: var(--wp--preset--color--query-pagination-numbers-current-base); } & .page-numbers.dots { padding: .5rem .6rem; border-radius: .25rem; color: var(--wp--preset--color--query-pagination-numbers-dots-contrast); background-color: var(--wp--preset--color--query-pagination-numbers-dots-base); } @media screen and (max-width: 599px) { & .page-numbers { display: none; } }",
It's like the media query fragment is completely ignored, bypassed. But not it's CSS inside that's still applied without resolution constraints.
To demonstrate it, I changed the media query code to @media screen and (max-width: 599px) { & .page-numbers { color: #f00; } }
And as you can see, that css inside the media query is still being applied in a 1024 resolution.
The theme is custom, made by me... But since it's working on 16.7.1 and only failed when I
Claim this issue to let others know you're working on it. You'll earn 20 points when you complete it!