3 ms·
CSS 2.1 defines a specific order in which user-supplied style sheets' declarations must be honored [1]. This ordering makes a lot of sense to me: author normal
by pcwalton 13y ago
CSS 2.1 defines a specific order in which user-supplied style sheets' declarations must be honored [1]. This ordering makes a lot of sense to me: author normal overrides user normal, but user !important overrides author !important. Can extensions easily replicate this behavior if the spec-compliant code is purged from the selector matching engine?
[1]: http://www.w3.org/TR/CSS2/cascade.html#cascading-order http://www.w3.org/TR/CSS2/cascade.html#cascading-order
- leobelle 13y ago! isn't as simple as that. CSS is cascading. If there are conflicting ! then rule specificity would be taken into account. If the rules have similar specificity the last one evaluated wins. I imagine user extensions are loaded at the end so in that case they would win.
- pcwalton 13y agoNo. !important supplied by the user is always higher than !important supplied by the author (and the opposite is true for non-!important), regardless of specificity. Specificity only comes into play when considering two rules supplied by the user or two rules supplied by the author. If user agent style sheets are removed from the engine, then extensions will have to start considering specificity when adding style sheets to the end of the list, because they'll all be considered "author" rules. But user style sheets shouldn't have to worry about specificity, per the spec.
- leobelle 13y agoThat would break how CSS works. I don't like it.
- mpyne 13y agoHe is describing how CSS is spec'ed to work right to you. The proposed Chrome change would be breaking how CSS works.
- leobelle 13y agoYes I understand, but I wouldn't want that in a chrome extension personally. It could make styling harder. When you nuke rules without considering specificity it can cause unintended consequences. If everything just followed regular CSS rules as if all CSS was applied by the author there would be less of a chance of changing something you hadn't intended to change.
- officemonkey 13y agoThe people who use user style sheets (especially !important rules) in CSS aren't particularly interested in your styling. They're interested in the content in a style that works for them. This is an important accessibility feature of CSS and I'm disturbed at any reduction in support for this feature.
- magicalist 13y agoNo, not easily. You can see that this is already the case in Firefox for Android, for instance, where you can't supply a user style sheet (the firefox profile is inaccessible to a user without root anyways). If you do want to provide user styles, Stylish is the featured (and almost universally recommended) extension for adding them. As you can see in the docs[1], though, anytime your !important rule comes up against an author's !important rule and you lose, the only workaround is to get more specific. (it should be noted, though, that while CSS 2.1 does specify the cascade order with a "must", the user being able to specify styles in the first place is a "may", so Firefox for Android and Chrome for Android (which still doesn't support extensions) are spec compliant, they just make overriding styles more work and more fragile in the face of author changes) [1] https://github.com/JasonBarnabe/stylish/wiki/Overwriting-page-styles#wiki-recommendations https://github.com/JasonBarnabe/stylish/wiki/Overwriting-pag...
- pcwalton 13y agoYeah, I guess what I'd like is an API for extensions like Stylish to use to add real user-level style sheets, in both Firefox and Chrome.