-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace hardcoded breakpoints in front-end CSS with more modular CSS #35848
Comments
That's definitely an important feature. 600px is very small for mobile screens, most of the frameworks collapse at ~700-1000px. It makes navigation looks messy if there are many links, they simply don't fit. |
@DeoThemes I have found in general that columns not collapsing until <600px results in some pretty extreme content squashing for more than 2 columns. I'd like to also point out that using |
Related: #12299 including a possible workaround covered in #12299 (comment) |
@cr0ybot I agree. There's a real need for grid layouts in the query loop block, and elsewhere, to respond at user defined breakpoints, and especially a need for columns to reduce responsively with screen size (beyond just going from, for instance, 3 columns above 600px to 1 column under 600px). Query loop block needs the option to define at least a middle ground option between say 600 & 100opx, but ideally at user defined points. |
UPDATE: The core columns block uses The part that worries me most is that a columns block that breaks without a breakpoint would probably need to have its columns' |
I finally got around to reading your blog post linked in that comment: https://kraftner.com/en/blog/building-your-own-wordpress-core-block-css/ Completely replacing the core block stylesheet is a workaround, but you end up in a situation that is very fragile. As WordPress/Gutenberg update with new/updated blocks, the replacement stylesheet is stuck at the old version. If it were possible to override individual block styles, I'd feel that is a more tenable solution. It looks like the should_load_separate_core_block_assets hook might provide a possible way forward for that? We should be able to override the stylesheet enqueue via the slug, though combined stylesheets are still loaded in the editor. I'm going to mess around with this to see if it's feasible. |
@cr0ybot I 100% agree that this is a terrible workaround which I'd love to get rid of. I see my blog post 50% as showing a workaround and 50% as an illustration of how terrible the current situation is and why it needs fixing. 😉 |
Also by using grid it would reduce the amount of CSS shipped most likely, especially if media queries were eliminated. I recently ran into issue trying to override the 600px media query and had to use !Important. I still use flexbox for items but grid is best for container type of layouts like columns. |
This is something I've experimented with since WP 5.0 was released and it's been a lot less fragile than I initially worried it would be.
I've been using something as simple as the following to achieve this:
|
For some blocks, for example the navigation block, it would be great, if it would be possible to change the breakpoint where the block uses the mobile / desktop navigation. |
I also think that adding a way for themes to define the breakpoints would be very useful. This setting could be exposed via Users and developers already have the ability to change the Either these breakpoints could be set as part of the layout or as part of a new These here are the breakpoints that Gutenberg currently uses in its scss: gutenberg/packages/base-styles/_breakpoints.scss Lines 5 to 13 in d8a4c9c
And looking at the small medium So I think those are the only two that would need to get exposed in theme.json by default. But ideally the system could be flexible enough so themes could use this to also define their own breakpoints on top of the core ones. |
Fully echo what @fabiankaegy said. |
I just stumbled upon this issue as it is one of my biggest bug bears at the moment working with core blocks. breakpoints should be possible to override via theme.json. Is there a solution being merged for this yet? I can see a lot of suggestions but no signs of a fix yet? This is a crucial aspect to responsive design and is holding Gutenberg back by not being customisable. |
Currently hitting this issue right now. Very frustrating that we cannot control this in theme.json. To be able to align the core breakpoints with my own custom breakpoints would be magical. |
+1 for breakpoint overrides available via theme.json. |
Is there any movement on this? The issue has been opened for 2 years now and seems to be important for a lot of developers. |
@WordPress/outreach surfacing this issue as our team is faced with this in every client theme we build. Are there any known issues that would prevent the theme.json to be extended to support this in the 'settings.layout' As @fabiankaegy suggested, having the ability to adjust small and medium would be fantastic. I'd love to have control of the large and xl breakpoints as well since we often need breakpoints around the 1440 and 1920 widths. |
This would be a wonderful way to bridge the gap between intrinsic and responsive. To have the means to set the breakpoints in Even if it was just a matter of being able to override the unit with CSS vars would be a win. I can’t recall what the common breakpoints are that exist and I’m on mobile, but using a theoretical example… WP currently provides this (again only an example and not true code coming from WP): Replace with this: |
@colorful-tones Unfortunately you can't use CSS vars to build media queries (as we learned the hard way). |
I forgot CSS variables do not work in media query declarations. 🤦♂️ |
Here is a solution (more of a workaround). https://gist.github.com/colorful-tones/22da9a7f6a1f5867903e5eff826567e1 It is nothing new and I think it is a derivative of @kraftner’s article https://kraftner.com/en/blog/building-your-own-wordpress-core-block-css/ I think it could be worth exploring extending ʼtheme.jsonʼ to allow for these breakpoints. |
@colorful-tones If I read this right what you're doing is adding CSS on top. My approach is about replacing it so you do not constantly have to fight against core styles. Having said that my blog post is quite old and dated by now. While still not great a more modern approach might be able to combine https://developer.wordpress.org/block-editor/how-to-guides/themes/theme-support/#disabling-base-layout-styles and what was proposed by @cr0ybot above. I wish I'd have the time to write a follow up post to the one you linked with these approaches. But doesn't look like it right now. Even if - still these are all just workarounds to the core issue: Breakpoints are hardcoded. And to change them the CSS custom property based approach for anything else from |
+1 for breakpoint setup in theme.json. Long menus look really bad at 600px (and up to 800px most of the time). |
+1 |
This feels like a critical need, as WordPress is still using pixel breakpoints, which is not responsive or accessible to the user's browser default font size. So as text size increases, pixel breakpoints happen way too early/late. And having these configurable in the theme, and even per block, would be great. |
+1 for breakpoint overrides available via theme.json. |
I don't understand why such an important thing wasn't done right away and is being postponed. Sometimes I need even 5 breakpoints OR do I need to set the sizes via the css clamp() property |
What problem does this address?
Hardcoded screen width media queries like the 600px breakpoint for the core/columns block poses a not-insignificant problem for theme developers. We either have to work with that specific breakpoint, integrating it with our design system (even if we don't agree with pixel-based breakpoints #16911), completely remove core Gutenberg front-end styles, or otherwise hack around the CSS which no one enjoys doing. Some of these styles are particularly egregious to work around because they involve
!important
declarations to override inline styles.What is your proposed solution?
I recently submitted a proposed solution using CSS custom properties #35808 and then immediately found out that this is not currently possible: https://bholmes.dev/blog/alternative-to-css-variable-media-queries/.
There is also no hook or other customization vector available to change the breakpoints. #19460
Regardless, I don't think that standard back-end breakpoints should cross over into front-end styles.
Instead, there are ways to write CSS for responsive layouts that do not rely on external breakpoints, but rather internal sizes. A good example is the "Switcher" layout from Every Layout. This approach, combined with some contextual CSS custom properties, would allow for easier manipulation of minimum-width of columns before they break into a single column, for example.
The challenge to overcome here is that this might not be a very backwards-compatible solution. Some themes out there in the wild are probably depending on hacky CSS workarounds to change the breakpoint of certain blocks, for example. However, I feel like this would be a more sustainable approach for future overrideability.
Here are the blocks I found that include hardcoded breakpoints:
This search URL should probably find all of them: https://github.com/search?q=%24break-small+repo%3AWordPress%2Fgutenberg++path%3A%2Fpackages%2Fblock-library%2F+filename%3Astyle.scss&type=Code&ref=advsearch&l=&l=
Other issues that have attempted to start conversations similar to this:
Related PRs:
The text was updated successfully, but these errors were encountered: