Using CSS custom properties in a block. #123
Replies: 4 comments
-
Beta Was this translation helpful? Give feedback.
0 replies
-
|
@mburridge this article should probably also cover the new Selectors API. This will be included in 6.3 and is a more official way to apply block support styles to different elements of a block. |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Conversation locked after. Continue discussion on the issue |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Now published: Styling blocks: empowering users with CSS custom properties |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The
Block SupportsAPI allows you add colour and spacing settings to your block with a simple definition inblock.json. However, this only allows "block level" styling, and is fine for simple blocks. If your block is more complex and consists of a hierarchy of HTML elements which need to be styled using the CSS cascade, and you want to allow users to have control over that styling, then another solution needs to be sought.This solution is not immediately obvious and involves using CSS custom properties (also called CSS variables) which get their values from the block attributes and passes them to the block's wrapping element's
useBlockPropshook. A similar task can be done withrender.phpin a dynamic block, where the CSS custom properties are instead passed to theget_block_wrapper_attributesfunction.The proposed post is a tutorial that illustrates using CSS custom properties in a block project.
Beta Was this translation helpful? Give feedback.
All reactions