-
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
CSS in the editor is sometimes too specific to override #17069
Comments
@markhowellsmead thanks for filing an issue. The code snippet you linked to sets I like that you included a specific example. It also helps a lot to cover why you think a changes is needed and to include reasons and examples showing why it's a problem in your view. We need to be precise because saying "CSS is too specific" by itself is not as actionable because it's so broad and there's already a lot of history as to why each piece of the code was setup as it was. It may help to note: what is your end goal? Where are you getting stuck specifically? Are you trying to override the width of full-width images so that they are not 100% full-width? |
The difficulty I'm running into is that the The entire site is otherwise hack-free and entirely built using very simple BEM practices; without having to override the editor's own, highly specific CSS, the following is an example of the remainder of the ruleset for the block in question. .b-courseteaser {
position: relative;
&__figure {
position: absolute;
top: 0;
right: 0;
height: 100%;
width: var(--courseteaser-image-width);
}
}
The generated CSS from Gutenberg is as follows; as you can see, excessively specific. .block-editor-block-list__layout .block-editor-block-list__block[data-align=full]>.block-editor-block-list__block-edit figure {
width: 100%;
} Edit: you mention that the rule “sets figure to 100% width when "full-width" alignment is set for an image” - although this is true, it also affects every single other block which contains a |
That's not what I found when I tested. Here are my steps:
Result: only the full-width image has |
@designsimply I do see what you mean. But try it with a full-width block which contains a figure element inside the main element. I would imagine that an image block containing a figure element inside a full-width column block will exhibit the same issue which I’m having. It certainly happens in custom blocks. It comes down to the rule being applied to any child figure element, not just immediate children. |
This no longer appears to be an issue in the cases which I originally tested. |
The CSS for the editor is sometimes so specific, that the only way to override a rule in a custom block's CSS is to use
!important
. (Or a unique ID selector, which causes problems when re-editing an existing block.)For example, the following definition forces all
figure
tags to be 100% wide; irrespective of where in the HTML structure they are.gutenberg/packages/block-editor/src/components/block-list/style.scss
Line 577 in 87da09e
This logic needs to be reviewed and the CSS written (and commented) in a more flexible way.
The text was updated successfully, but these errors were encountered: