Using :not() & nonexistent ID to create specificity for targeted unique elements (Hackity hack)

While simplifying my CSS I began playing with specificity as it applies to unique elements/objects "trapped" within a library or framework. I found using the ":not" selector on an element with a non-existent id (such as "ordinary" used in the codepen) allowed for very targeted css without using "id" . This feels evil but thought it would be better to ask a community for a second opinion. Is this technique to increase specificity for specific unique elements a devilishly good idea or just pure evil? šŸ¤” https://codepen.io/Snap-Riley/pen/XWvmLab
No description
6 Replies
Snap Riley
Snap Rileyā€¢4w ago
I apologize in advance if this post is a little unclear. This is my first post in discord!:thanks:
Rowe2ry
Rowe2ryā€¢4w ago
Iā€™d say itā€™s better than an !important but itā€™s in the same vein of ā€œprobably shouldnā€™t use if you can avoid itā€
Restemat
Restematā€¢4w ago
Relevant article on using something similar to this technique to override unlayered styles https://blog.kizu.dev/extra-nesting-specificity/
Extra Nesting Specificity
Exactly aĀ month ago, IĀ started aĀ thread onĀ Mastodon about unlayered styles, which led toĀ meĀ bumping the corresponding CSSWG issue aĀ bit more than two weeksĀ ago. There was one CSS hack IĀ did share inĀ this thread which IĀ did not yet write about inĀ this blog, which Iā€™m going toĀ doĀ now!
Snap Riley
Snap Rileyā€¢4w ago
Thanks for the article. It's directly on point. I agree, it's better to not do this at all. (Thus the title containing "hackity bad hack" šŸ˜† ) But how does one perform the CSS styling when you are backed into a corner due to vendor library CSS restrictions? Are there other techniques that would work?
Restemat
Restematā€¢3w ago
What we need is the ability to assign stylesheets linked with the html link tag to cascade layers. This has been proposed by Miriam Suzanne https://css.oddbird.net/layers/link-layer/ and after a couple of years of discussions is now at a design review stage https://github.com/w3ctag/design-reviews/issues/970. But until this has been approved and implemented in browsers I think the *:not(#a#b) {...} trick is as good as any in a pinch šŸ¤·ā€ā™‚ļø
GitHub
Issues Ā· w3ctag/design-reviews
W3C specs and API reviews . Contribute to w3ctag/design-reviews development by creating an account on GitHub.
Snap Riley
Snap Rileyā€¢3w ago
Now that is an interesting proposal. Thanks for the feedback.
Want results from more Discord servers?
Add your server