-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Front-end style.css specificity audit #11779
Comments
If there are concerns with individual cases around css specificity, we should create specific issues. At the same time, I value the desire to discuss and be on the same page regarding what is needed overall. Could you perhaps start with a specific example of one thing in a comment here that you find unnecessarily nested and overqualified and explain why? Another idea could be to start by auditing a single block and report your findings separately to see if that approach is more actionable. |
Let's start with button CSS PR #12005button.wp-block-button__link
0,1,0
Is there a reason .is-style-squared
0,2,0
.has-background
0,1,0
So currently Twenty-Seventeen needs a
text-color current specificity: 0,4,0
0,1,0
0,1,0
0,1,0
|
cover*wp-block-cover-text
0,2,0
Or even better, is there a situation where this would have undesirable results?
.wp-block-cover-image a
Why couldn't we replace all that with this?:
Or even better, use .has-background-dim
0,2,1
|
embeds.wp-block-embed__wrapper
Replace all that with this:
.wp-block-embed__wrapper::before
Replace all that with this?:
.wp-block-embed__wrapper iframe
0,2,1
or even:
aspect-* .wp-block-embed__wrapper::before x7
0,3,1
figcaption
Maybe a little off topic but I'm noticing several places where
|
I'm thinking specificity is a problem, but also that the CSS has so many colors and font sizes and paddings and margins. It shouldn't have any of that. The theme will handle all that naturally. But especially colors should not be in styles that affect content. (they are okay for editor interface) The specificity problems I encounter are on blockquote, pre, and code elements, (even h1, h2, h3 have color styles in the editor). Because my theme styles the elements, then the GB styles are styling the classes that wrap the elements, the GB styles override (more specific). |
This is something totally should be looked at during 5.0.1 perhaps. I am going to remove the design feedback label as this firmly sits in code. It won't or shouldn't effect any design. |
My editor-style.css file for my custom theme contains the same rules as my main style.css file but it contains !important at the end of each line. Why? |
Reduces specificity in core Cover styles to ease clashes with theme styles. This has been explained and discussed in further detail here WordPress#11779 (comment) The cover text color was added to the parent `.wp-block-cover` element so that text`.wp-block-cover-text` and links`.wp-block-cover-text a` could `inherit` the color. This drys up the code and allows for single class selector overrides. I've also removed the references and styles for `.wp-block-cover-image`. I couldn't find anything mentioning a planned removal date and assumed now would be OK to do so..? I'm also not sure what the `h2` styles are referencing. Is an `h2` something I'm missing within the Cover Block? I'd like to remove if not.
There's been a lot of changes and reductions in specificity as part of the style engine work, variations, global styles, etc. It's still an active area of improvements, so if there's some specific rules that need improving let's tackle those separately. |
I know it's been mentioned but I couldn't find a relevant issue to attach this to. So I've opened this one to give the conversation a home.
Describe the bug
Many selectors in the
build/block-library/style.css
file are unnecessarily nested and over-qualified.This makes it difficult for themes and plugins to override and adds weight to the front-end file.
Wasn't sure if a single or multiple PRs would be better so I did a quick run through
build/block-library/style.css
and created a gist with comments where I think things could improve.https://gist.github.com/m-e-h/2e3ab2ee68825bd2728edd52be96be95
I'm not super familiar with how the styles got to where they're at so some of my suggestions are probably not possible. I'm also sure there are some areas for optimization that I missed.
Similar
#1720
#11677
#10067
#11752
The text was updated successfully, but these errors were encountered: