-
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
External stylesheets can't override inline core styles #40159
Comments
See also #41230. |
Speaking to I'm referring specifically to There are a couple of PRs trying to address this bug, namely #40875 and #39870. As you've noted it highlights a broader challenge regarding the specificity of all CSS properties defined by layout. In the spirit of the issue about standardizing CSS classnames/tokens, an exploratory PR is out there that generates
What are your thoughts about an approach like that? The layout implementation affects a number of block and site layouts so it's all a bit like tip-toeing on thin ice above a sea of radioactive sharks, but I'm of the view it needs to be refactored, and it will have to before we add further layout options to Gutenberg. |
Thanks for looking into it, @ramonjd, I appreciate it. Some colleagues and I discussed the problematic descendant selector in #36135 last year and we came to a similar solution: using semantic class names makes a lot more sense. I would suggest:
|
I would also note that |
I generally like the idea of abstracting layout out into predictable classes like
I'd also agree with the use of |
Related #38126 |
Related #41431. |
Still a problem. |
Still a problem. |
@EmSixTeen Going by the custom property names, that specific implementation is most likely coming from a third-party solution. (Bumping this through @WordPress/outreach to get some visibility.) |
I'm afraid I need to hold up my hands and say I've made an error here in thinking the cause is WordPress/Gutenberg. The style.min.css is my enqueued stylesheet, and I believed that the inline style was WP/Gutenberg. |
This problem is still occurring and is more prevalent with WordPress 6.6. Specifically:
The inline core CSS overrides my linked styles because it comes later in the cascade. |
Regarding this specific element issue noted in the comment above, a fix is available in Gutenberg and was released today in v18.8. For WP6.6, there is an open ticket with a custom plugin build that can be used to evaluate the fix in the context of WP6.6. The fix will be included in the 6.6.1 point release but I unfortunately don't have a specific time yet for when that point release might happen. I'd recommend keeping an eye on https://core.trac.wordpress.org/ticket/61660 for further updates. |
Description
I'm trying to override inline rules, e.g.
.wp-container-1 > *
, using rules in a stylesheet referenced through an enqueued stylesheet. The specificity of this selector is 0,1,0.Using the selector
.wp-block-group
in the theme CSS is also 0,1,0 and so it should be able to override the inline rule.However, it cannot because inline styles take precedence over any linked stylesheets.
See also #36135 in particular, as well as #35840, #34047, #29705, #17511 and #39971.
Step-by-step reproduction instructions
Enqueue a stylesheet containing the following CSS. The
max-width
doesn't override the inline core CSS unless!important
is used.(In practice, the rule is being applied to a custom block with a custom class name, which must always be full-width and whose
max-width
- or alignment - may not be adjusted in the editor. The example class name.wp-block-group
is only being used here for example purposes.)(The use of
!important
introduces a large number of subsequent priority rule problems and a large number of experts have been advising against it for a very long time. e.g. MDN Web Docs.)Screenshots, screen recording, code snippet
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: