-
Notifications
You must be signed in to change notification settings - Fork 384
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
Reduce length of specificity-hacked CSS selectors #6312
Conversation
5d677c0
to
76577fa
Compare
The lack of I don't think this is a problem because the specificity from the IDs has much greater impact. But it's something to be aware of when testing. |
Plugin builds for 70fcaeb are ready 🛎️!
|
@swissspidy Asking for your review as I know Web Stories uses a lot of inline styles which could be impacted by this, although perhaps not due to GoogleForCreators/web-stories-wp#6783. |
@westonruter sorry for the late reply. Correct, I could not see a difference for Web Stories because of GoogleForCreators/web-stories-wp#6783 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. The savings in stylesheet sizes are amazing!
I was a bit concerned if it is okay to have selectors targeting elements having multiple ID attributes. However, according to the W3C docs, it is valid:
If an element has multiple ID attributes, all of them must be treated as IDs for that element for the purposes of the ID selector. Such a situation could be reached using mixtures of xml:id, DOM3 Core, XML DTDs, and namespace-specific knowledge.
One potential issue I noticed is that the new selector is not supported in IE11:
Chrome to the left, IE11 to the right (via BrowserStack)
The Custom HTML block content is:
<p style="color:red!important;">This is red !important text</p>
<p class="test-1">This is red text from inline stylesheet using :not(#_#_#_) method</p>
<p class="test-2">This is red text from inline stylesheet using :not(#_):not(#_):not(#_) method</p>
<style>
.test-1:not(#_#_#_) { color: red; }
.test-2:not(#_):not(#_):not(#_) { color: red; }
</style>
Since, as of WordPress 5.8, IE11 is no longer supported and also since AMP is meant primarily for mobile devices, I wouldn't regard this as a show-stopper.
Good find! And good to know. I agree that it isn't a show-stopper. |
✅ QA Passed. After adding HTML markup given description in post content. it reduced the length of CSS and does not use the |
Summary
I realized that we can compress the size of our CSS specificity hacks quite a bit by eliminating the redundant
:not()
pseudo selectors. So instead of:not(#_):not(#_):not(#_)
we can refactor this to be the equivalent specificity:not(#_#_#_)
.Additionally, instead of adding a
:root
ancestor selector, we can instead just appending the the:not()
to the original selector.Lastly, the prefix ofThis is kept as-is for now to prevent any unintentional regressions..amp-wp-
can be reduced down to just.amp
.Given this example HTML from #1313:
Before this would have resulted in the following which is 422 bytes after minification:
With the changes in this PR, the same CSS is reduced to 235 bytes after minification:
This is a ~44% reduction in the resulting CSS.
This also fixes issues with
amp-next-page
for CSS selectors that are targeting elements in shadow DOM. Fixes #6909.This also adds a tooltip to the
:not(#_…)
pesudo-class selectors in the stylesheets metabox:Checklist