-
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
[Feature Request] Add wp-block
class to all the blocks
#6639
Comments
While not as explicit, would the following work? [class^="wp-block-"] {
margin-bottom: 60px;
} |
👍 There's no reason why this shouldn't be the case and the sooner we decide on the class name the better. This would also be useful if Gutenberg decides to take over dynamic CSS injection. @aduth It should be its own |
We offer the filter which allows to modify the default class name: What about using the following instead: function addBlockCustomClassName( className ) {
return 'wp-block ' + className;
}
// Adding the filter
wp.hooks.addFilter(
'blocks.getBlockDefaultClassName',
'my-plugin/add-block-custom-class-name',
addBlockCustomClassName
); |
This probably needs a decision for the "try" milestone. |
I don't feel strongly about adding |
One question: is the idea that I imagine only core blocks (you wouldn't really be able to enforce it on 3rd party blocks) but either way I like the idea. |
At present, we are enforcing a specific class naming convention for third-party blocks unless they specifically opt out. I think it would be reasonable to enforce the |
This came up in a weekly #core-editor chat (link). We decided to punt on this for now because:
|
From a user perspective it's very hard to understand what prevents adding a class of |
What do you think, @gziolo? It sounds like the existing solutions we have here aren't good enough. |
I think there are still blocks which don't have any class name provided by design like Paragraph, Heading or List blocks (all of those with |
Isabel @tellthemachines perhaps this might be an issue for you to take a closer look at? |
As shared by @gziolo not adding this class to all blocks has been a conscious decision, some blocks also don't have wrappers (shortcodes, embeds)... I think for the use-cases mentioned here, our approach lately have been to add settings to theme.json to define things like block margins, layout... and avoid CSS as much as possible. I'm going to close this issue for now as for me the ship has sailed here. |
Hello, can we please reopen this issue? I do not feel this is adequately resolved using just Not only is this very limited in scope, this workaround excludes blocks like headings and paragraphs which by default do not get any gutenberg specific classes at all. This can be very problematic if people are using custom blocks and interspersing them with core blocks in their themes (like I am right now). I would say the most common use case for wanting a common class across all gutenberg blocks is to contain them in a container wrapper. Currently you can wrap each block with the For example, if I used a button within a columns block, and wrapped each block using the .wp-block-buttons > .wp-block-button.wp-block-button__width-100 {
margin-right: 0;
width: 100%;
} As you can see, if a custom wrapper is applied to gutenberg blocks by a developer, the default css for alignment will not be applied at all because it is based on a depth hierarchy. This means that we need to go in and manually test each and every core block to see if any styles conflict!!!! This is very inefficient and I would prefer to be able to target blocks specifically rather than whitelist each and every block for each different project. This is why I would like to see a default class be implemented at the top-most level of each core block. Also, I am using ACF blocks, so honestly using a JS based filter is not an ideal solution. Now I realise that adding a common class to headings and paragraphs may need some manual css finessing by the developer in a columns block. However adding a default class would be vastly more appealing than the current set up because it would mean less work and time spent testing each and every block. Also bear in mind that adding a single class doesn't even affect the front-end at all so if this class isn't used it won't affect the site's display. This addition is purely to make developer's lives easier. Thanks for your considering and I appreciate the work being done on this. But please, from a developer and even user perspective (asking admins to use groups can be burdensome and confusing to the writer) this workflow needs to be improved. |
I agree that alignments inside containers in the biggest use-case for this. This is something we solved using the "layout" config in theme.json by making sure theme authors don't have to provide this kind of CSS at all. |
I see, I was not aware of a theme.json. I do like the concept of it but I can see this getting wildly complex very quickly. Is there a way to set global settings that affect all core blocks? eg. I would like to set |
There is for the max-width yes but not for the margin yet (it will come). Expect a dev note (post detailing all of that) very soon on make/core as theme.json and layout are shipping in WP 5.8. |
What about responsive settings for max-width, margin, and padding for all blocks? |
Exactly....this is why I would prefer a single class linking all the core blocks together. It allows for the greatest flexibility; CSS in it's purest form instead of nested json values. Also keep in mind that custom styles that are applied to blocks may be less than ideal in columns. eg. if you applied To be honest I think a single class will solve this issue in a much cleaner and more manageable way but I will await the documentation for theme.json. :) |
And responsive variations on other things like font size? This theme.json concept might quickly become a kluge. In order to concisely and naturally represent the full feature-set of CSS you need something like... well, CSS. |
Gutenberg doesn't have built-in responsive controls yet, discussions and iterations on that aspect are yet to come but the global direction is more toward "intrinsic web design" rather than "responsive web design" |
Ideally design follows a system, but ultimately comes from the imagination- unbounded by technical limitations. CSS has evolved to accommodate a designer's wildest imaginations in a standardized way... it's quite a big wheel to reinvent. |
theme.json is not meant to replace CSS but to absorb a lot of structural and appearance concerns as a block-first API that is more agnostic of the environment a block is rendered (for example, mobile native that lacks CSS, etc). It doesn't cascade in the same way that CSS does and handles composition in a way that is more tied to specific block semantics (like a nested block or template areas). The result should be a theme.css file can become much leaner and manageable. Regarding the specific issue of a generic class, it'd be fine to explore a filter that just appends |
I think this sounds like a good solution, although it would be nice if it was able to be serialized too (or any other custom class a developer may want to add to a block using the filter). I understand that the resulting markup is intended to be kept as clean as possible, but considering that paragraphs and headings are considered separate blocks in the editor, I think it makes sense for them to be treated the same in the resulting markup too. Paragraph and heading tags are by default block level elements so I don't think it is strange to give them their own class if they are generated by Gutenberg specifically. But that is just my opinion. An option to toggle the |
It would be handy to have
wp-block
class added to all the blocks in addition to block specific class.This would be useful if we want to set say, a bottom margin to all the blocks in CSS.
Ex.:
Instead of having to write
we could simply write
The text was updated successfully, but these errors were encountered: