-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Block styles: add block instance custom CSS #56127
Comments
@carolinan, @aristath just pinging you in case you are interested in looking at this since you worked on the global styles block custom CSS. |
I know that page specific CSS is a highly sought after feature, and this is a variation of that. I have one concern, it can potentially make it more difficult to find out where a style is from. |
I have seen this mentioned somewhere, but couldn't track it down today. It may have just been comments on another issue.
Also related to this: |
I am back from my time off for the holidays and have the availability to work on this now. |
If we save the custom CSS as a block attribute, it has the potential to both break and be very large. 🤔 |
What about |
@aristath I don't follow, your comment is regarding the output, not the storing? |
My own concern is this part of the block supports: |
I'm talking about storing the custom-css data. Another option would be to introduce a new, hidden |
Ideally as little as possible should be in the HTML comment or saved in the post_content, I like the idea of using the ID as the attribute on the block; But I don't know how to code any of this, while it is not difficult to add a new block supports that just uses the input. The block support "just works", and it can be filtered. |
Not sure if it's helpful, but this plugin adds this functionality. Of course it's preferable to have it in core, and one downside of this plugin is the CSS doesn't apply in the editor, which is less than ideal. But, it's exciting to see what one can do with per block custom CSS. |
What problem does this address?
Currently, it is possible to add custom CSS for a given block type, but it is not possible to add custom CSS to a specific instance of a block in a given page/post.
There is a workaround for this by adding a custom class name to the block, and then targetting custom CSS to that selector via the site editor custom CSS input. However this involves a two-step process which may not be obvious to some users, and also many content editors may not have access to the site editor.
See #48331 for more background discussion and suggested solutions.
The proposed solution
In the block inspector panel in the post editor (most likely in the Styles tab) add an
Advanced
panel that is collapsed by default and has a custom CSS input box, similar to one in the block inspector panel in global styles.This should operate the same as the global styles block-specific custom CSS in that a top-level selector is added automatically so only the style declarations need to be added and nested selectors can be handled by prefixing with a
&
. See #46571 for more detail about the global styles block custom CSS.Tasks
"style": {"customCSS": "color: purple"}
and also decide if blocks will need to opt in to use it, or will it be opt-out by defaultThe text was updated successfully, but these errors were encountered: