Open porg opened 1 year ago
Thank you for the report @porg. I am going to add a couple of screenshots with a simple example of what you describe to make sure I understand:
You add a per-block style:
But you have some blocks of that type that should be styled different:
... hence, your only option is to add a global style.
Were you referring to this?
I also see how trying to target different parts of the block can be very challenging in the case of complex blocks. There are a couple of tips in this article: https://wordpress.org/documentation/article/styles-overview/#applying-custom-css but I see how it is very limiting at the moment.
Is it possible that "Additional Block CSS" gets "a bit smarter" with what it prefixes
Do you have any thoughts on how we could iterate on the "Per block CSS" interface to incorporate more flexibility?
Were you referring to this?
Yes, I was referring to what is depicted on your screenshots.
Do you have any thoughts on how we could iterate on the "Per block CSS" interface to incorporate more flexibility?
https://wordpress.org/documentation/article/styles-overview/#applying-custom-css
Though I know the underlying architecture of theme.json
and theStyle Engine
only on the level of a designer / amateur frontend-dev, but not more. So some ideas may need adaptation or discarding.
Pure attribute names get wrapped into the appropriate selector. That works fine already. And shall be guaranteed to continue to work, also if we the rest gets added functionality.
I prefer approach 2:
Thank you for the detailed outline. I see pros and cons on both solutions 🤔
Once again I need to resort to @annezazu's expertise 🙏
👋🏼 Thanks for tagging me in! To take a step back, CSS is intended to be a gap filler with the long term aim for as much as possible to be handled by the site editor itself. I'm sharing that to ensure the wider context is known for how and why custom CSS was added. Ideally, in the future, you won't need to rely on this to create the customizations you want. Of note, there are these follow up items:
Add inline code completion and linting to input box similar to customizer. Provide list of blocks that have had custom CSS applied at the block level.
Professional theme.json developers/modders possibly can achieve that by writing a proper block style with inline custom CSS as JSON values.
Generally speaking, this is what's currently possible. In the future though, there's work to be done to both expand styling options through things like https://github.com/WordPress/gutenberg/issues/40966 and thoughts around having a way to save a custom CSS class as a block variation: https://github.com/WordPress/gutenberg/issues/7551 I might comment on that latter issue personally.
@glendaviesnz I want to get your thoughts here, particularly around why there isn't a custom CSS field for block variations. That felt a bit surprising but I imagine there might be some technical limitations here.
@annezazu thanks for providing the bigger picture and long term goals.
As you seem to have knowhow in that subject domain: Could you please amend the documentation with the status quo on Custom CSS particularly to answer https://github.com/WordPress/gutenberg/issues/49415#issuecomment-1495893626:~:text=Please%20improve%20the%20documentation%20of%20this%20section ?
Ironically, I did an initial sweep of that doc right before 6.2 to help out that team: https://github.com/WordPress/Documentation-Issue-Tracker/issues/675#issuecomment-1486026994 and then @mrfoxtalbot and co helped flesh it out after the fact. Here's an issue to address this: https://github.com/WordPress/Documentation-Issue-Tracker/issues/747 If I can, I'll loop back personally.
@glendaviesnz I want to get your thoughts here, particularly around why there isn't a custom CSS field for block variations. That felt a bit surprising but I imagine there might be some technical limitations here.
I didn't have much involvement in the block-level CSS sorry, I mostly handled the global level, @carolinan may have more of the background on this.
The per-block custom CSS field is not intended to target these additional selectors. It is intended to be as simple as possible for end users, not developers.
About the documentation, the article you linked to is for users, not developers, so I do strongly disagree that it should cover topics like what post-processing is used.
So I summarize:
attribute: values;
only and not targeting particular elements of a block with CSS selectors (the prefixing/suffixing is a blackbox, which one must not know and which will remain undocumented).wp_enqueue_block_style()
.So I will use mostly 1, skip 2 due its very limited nature, and fall back to 3 in the few cases where really needed.
A user should not be required to know what a prefix is. They should trust that the CSS is added to the block they selected in the menu: and it is.
Exactly that expectation was the start of my journey!
I have the impression that we are discussing two things in paralell here:
Regarding the first item, I opened a separate thread here https://github.com/WordPress/gutenberg/issues/49531 If we do not want to make the end-user documentation excessively complicated, we should at the very least include a link to the relevant developer article where this is covered. I discuss the need to cross reference developer and end-user documentation with @juanmaguitar a while back and this is a perfect example.
About the second item, I do not see a clear path to fix this without going a very complex rabbit hole. I would recommend polishing the current interface and gather feedback from users to understand how useful per-block CSS really is.
Wanted to cross reference this issue too as it relates to this conversation around "adding a custom CSS field to block style variations":
These are two separate issues:
Put "border-style: dashed;" into a "custom block CSS" and instead of overriding the visible border's style (which was solid) I got nothing, and when using "border: 2px dashed red;" I got another border around the existing visible border. Why: Because the block author had applied the border not on the block level but on the element level (some deeper nested element). Only from this arose the need for an element-level CSS selector.
I am not able to reproduce this, the second issue. Can you provide the full details, including which block you are using and wether or not you were trying to override a style variation here?
If I understand correctly from discussions in related issues, the plan now is to add a CSS input field to the style variation UI. https://github.com/WordPress/gutenberg/issues/49602
User Goal
As a block theme tweaker (advanced user, designer with CSS knowhow, but no developer):
.has-outline-dashed
on a block instance like a Button block.TL;DR — My User Experience
If the attribute you want to override corresponds not to the block-level (as in BEM) of your block, but on an element level ...
Followup
My full testing
1) If I wanted to overwrite the default block style, it works easy:
Global Styles → Blocks → Button → Additional block CSS
!important
necessary2) If I wanted to overwrite a particular block style "Outline", working with the same method fails.
Global Styles → Blocks → Button → Style Variation "Outline"
3) Select a button block instance → block settings → Advanced → Additional CSS Class(es)
has-border-style-dashed
..wp-block-button
.wp-block-button__link
a) The only way I managed to select and override it was:
Global Styles → Additional CSS
b) Cleaner but failed attempt: Global Styles → Blocks → Button → Additional block CSS
has-border-style-dashed
.b1) Additional block CSS:
Outcome in
<style id='wp-block-library-inline-css'>
.wp-block-button__link
.b2) So I try this now:
Outcome in wp-block-library-inline-css:
b3) Hence I tried to formulate a selector in the spirit of "has a parent with class .has-border-style-dashed":
Outcome in wp-block-library-inline-css: