Post Archive
› March 11, 2003
A third css hack
During my search for the powers that will finally grant me eternal life - in other words while programming my ViewStyles bookmarklet - I found the grounds for yet another css hack, working on the stylesheet level. This one is a bit special, as it excludes the stylesheet from compliant clients while displaying it on non-compliant. It's the Alternate Stylesheet Hack. From my testing (Windows only), it seems like mozilla is the only browser that complies to the specs on this issue.
Update: Seems like most browsers are accounted for: Safari/Konqueror and Mozilla/derivates are the only modern browsers it work on.
Comments
1. March 11, 2003 11:29 AM
2. March 12, 2003 11:12 PM
Quote this comment
ksmith Posted…
Nice catch. The fact that the Gecko & KHTML folks agree on the implementation carries a lot of weight with me, but I'm not 100% sure of the correct behavior here. The spec says that "If two or more LINK elements specify a preferred style sheet, the first one takes precedence.", but it doesn't say what that means, exactly. Are the subsequent 'preferred' style sheets supposed to be demoted to alternates, or are they to be ignored altogether? Also, as far as I can tell, there's no mention of the STYLE element's role in all of this. So, why is it being ignored?3. March 13, 2003 07:43 AM
Quote this comment
liorean Posted…
One of the problems with the W3C specs are that some information that really belong in one spec sometimes appear only in another, and some things are partially explained in a number of specs but never explained in whole. This is one of the cases where I'd say the wrong spec (HTML instead of CSS) specify the mechanism. The interpretation may of course vary, and it doesn't say anything about the xml stylesheet mechanism... The reason it only handles http headers/meta tags and link tags, is that it's specified under the "External stylesheets" instead of under the main stylesheet section. Well, as for reasons for my interpretations of the mechanism described, here you have the deal:- "Authors may specify a number of mutually exclusive style sheets called alternate style sheets." - In other words, only one theme (all stylesheets with the same title) may be preferred.
- Further, "The author may specify that one of the alternates is a preferred style sheet." implies that alternate is the natural state of titled stylesheets, and preferred is something to be determined from the data available.
- "Authors may group several alternate style sheets (including the author's preferred style sheets) under a single style name." - What I like to call a "theme", to avoid name usage confusion.
- "User agents must not apply alternate style sheets with a different style name" - This is the rule that the non-conmpliant clients breaks.
- "If two or more LINK elements specify a preferred style sheet, the first one takes precedence." - This here can, as you say, be interpreted in several ways, but I think the natural way to interpret it is that if the author tries to promote an alternate theme to preferred, but the preferred theme already has been determined, the client shouldn't promote the theme.
4. March 15, 2003 12:09 AM
Quote this comment
ksmith Posted…
I think the reason this mechanism is described in the HTML spec (as opposed to CSS) is that it needs to account for other style sheet languages, like JSSS. Regardless, it reads like a draft, and doesn't seem very well thought-out.5. March 15, 2003 04:25 PM
Quote this comment
Nate Posted…
Wow this is an interesting hack! We can add Safari (v60) as a browser that parses correctly, like Mozilla. As one might expect Camino (moz based) also parses correctly. IE 5.5 for Mac does not get it right.