-
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
Additional Block CSS: Selector impossible if attribute is not on block-level but on element-level (as in BEM) #49415
Comments
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: 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.
Do you have any thoughts on how we could iterate on the "Per block CSS" interface to incorporate more flexibility? |
Yes, I was referring to what is depicted on your screenshots. Identified base problem
Please improve the documentation of this sectionhttps://wordpress.org/documentation/article/styles-overview/#applying-custom-css
I have some ideas how to improve the Additional Block CSS UI.Though I know the underlying architecture of Existing solutionsPure 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. Idea
Approach 1 (short term): Single textarea with available selectors visible as click links above the text area.
Approach 2 (long term): From the manifest the UI automatically creates different text areas
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.
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 #40966 and thoughts around having a way to save a custom CSS class as a block variation: #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.
|
Ironically, I did an initial sweep of that doc right before 6.2 to help out that team: WordPress/Documentation-Issue-Tracker#675 (comment) and then @mrfoxtalbot and co helped flesh it out after the fact. Here's an issue to address this: WordPress/Documentation-Issue-Tracker#747 If I can, I'll loop back personally. |
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:
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 #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:
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. |
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
Global Styles → Blocks → Button → Additional block CSS
!important
necessaryGlobal Styles → Blocks → Button → Style Variation "Outline"
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:
The text was updated successfully, but these errors were encountered: