-
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
Editor stylesheet CSS specificity issues #10067
Comments
Tested and confirmed with the following steps:
Result: I expected the line height to be 3 (exaggerated for visibility) and it wasn't.
|
This issue is great for a specific case and to see if we can improve something by continuing the work started in #9008. There is another issue #9534 which asks for feedback related to styling, and I thought I would point you there in case you would like to contribute to that conversation—which is more about critical thinking on the approach for styling on a more general level.
Thanks! Let's ask about this. @youknowriad, would it help to have more examples here? |
Yes, this is very useful and I expect we polish this over time. Most of these styles can be resolvers by changing the way they are being applied but we need to do these changes with care. A list of specificity issues would be great to have. @jasmussen might also be interested in this. |
The selectors I've noticed so far are:
All of the above seem overly specific and hard to overwrite. On the other hand, trying to import custom form styles into the editor have been a challenge as they can easily overwrite the inserter button styles for example. In this instance, I think the styles should have higher specificity, as I can't think of a situation where these should be trumped. Possibly not related and let me know if you would like a new issue, but noticed another bug in the editor.
Produces this which styles the blocks background, rather than the editor background like I expected:
It could be the case that I'm using the new feature incorrectly. |
Another unnecessarily specific block is the Code block: in block-library/edit-blocks.css we have:
in editor/style.css we have:
Since |
A little less specific would be:
This already exists:
|
This should be considered a blocker for API freeze and 5.0. Theme authors can't effectively implement block and editor style support until CSS specificity requirements can be finalized. This also impacts bundled theme updates, which will set the precedent for theme best practices. |
Specificity issues are also blocking work we're doing to make existing themes Gutenberg-friendly. We currently have to add more specific rules for editor widths in order to override default editor block styling when using For example, the CSS in the Gutenberg theme support handbook to change editor width looks like this: /* Main column width */
body.gutenberg-editor-page .editor-post-title__block,
body.gutenberg-editor-page .editor-default-block-appender,
body.gutenberg-editor-page .editor-block-list__block {
max-width: 720px;
}
/* Width of "wide" blocks */
body.gutenberg-editor-page .editor-block-list__block[data-align="wide"] {
max-width: 1080px;
}
/* Width of "full-wide" blocks */
body.gutenberg-editor-page .editor-block-list__block[data-align="full"] {
max-width: none;
} But this has no effect when using We are currently using more specific rules as a workaround (with an extra body.wp-admin.gutenberg-editor-page .editor-block-list__block,
body.wp-admin.gutenberg-editor-page .editor-default-block-appender,
body.wp-admin.gutenberg-editor-page .editor-post-title__block {
max-width: 732px;
} |
When using .wp-block {
width: 732px;
} |
Thanks, @youknowriad. It looks like additional hacks are also required beyond that to handle block alignment and full/wide cases: Once a method is finalised it would be good to update the handbook at https://wordpress.org/gutenberg/handbook/extensibility/theme-support/#changing-the-width-of-the-editor, which does not currently reflect the |
I think it would make more sense for |
Agreed we should try to refactor the editor styles to apply to the editor's container instead of the block's wrapper. The downside though is that it can affect the UI bits (toolbars, movers...) so we need to be careful there and check for feasibility first. |
The UI bits are definitely the issue when scoping beyond the block itself. #10178 But But I think globalizing the CSS scope, even more, may be a move in the wrong direction. |
@m-e-h actually raises a good point, and also we know that the styles are reasonably well scoped because of nested blocks. Otherwise, the styles mapped to I think simply changing |
I've run into several cases like that, in the editor, as well @chrisvanpatten . I've found that |
I'm planning to try this in the days and see if it's viable
|
Leaving a few notes over here from Twenty Nineteen land... There are a few things we've been trying to customize that've been difficult with the current stylesheet setup:
Since those last 3 bullets are outside the scope of the usual injected CSS file, we've added a second, un-modified CSS file to house those styles. Calling two stylesheets for the editor styles isn't ideal, and we hope to bring those into one, once it's possible to do so. |
Thanks all for your input. I opened #10956 which changes the wrapper where we apply the editor styles. Hopefully, this solves a lot of these issues. It doesn't solve everything though. I'd appreciate some help testing the PR and once we get it, let's try to split this massive issue into discrete issues to ease tracking and solving those. Thanks |
Re-tested with |
^ Just noting that this line height issue should be gone now, as we're no longer using the |
Noting that it would be good to maybe close this issue right now and do smaller ones as we made a lot of improvements recently for these styling issues? |
Yep, I think that would be good. Even though we already have many tickets in the repo, I would rather have 10 separate, small tickets, than one meta ticket. |
Can you point all the issues related to this? I'd like to take a closer look. |
No, that's the point, these issues would need to be created, one ticket for each issue that hasn't been addressed. |
Is there anything still left to address on this ticket? I notice that the issues described on the description have been fixed, as well as the ones mentioned on this comment, this comment, this comment and this comment. We should, in any case, create new tickets for any remaining issues before we close this one. But my question here is if there are any remaining issues, among the ones mentioned on this ticket, to be addressed. |
@tellthemachines I would tend to agree, good assessment. It's very easy to reopen this ticket if we close it in error, people can comment and ask it reopened and we will. So I'll go ahead and close it and direct to
[Feature] Custom Editor Styles
|
Describe the bug
Editor stylesheet CSS specificity issues.
To Reproduce
h2
line-height
rule is being overruled by a few rules in core with higher specificity:Expected behavior
Core styles should have less specificity to allow for an easier time adding a comprehensive custom editor stylesheet.
Could the above rules not be written like:
This allows the editor stylesheet to correctly trump the core styles.
This is only a brief example, but I'm sure there are others. I'd be happy to list all problematic styles that I find if it helps.
Additional context
Gutenberg 3.8 and WordPress 4.9.8
The text was updated successfully, but these errors were encountered: