Proposal: Hack Free CSS with the @unsupported Directive
chriseppstein.github.com
chriseppstein.github.com
Now, as a human looking at a syntax highlighted source file, my parsing is broken. All the differently-colored comments that I should be able to ignore suddenly have to be scanned because they might affect runtime somehow, and certainly any machine-based parser gets unnecessarily more complex.
Also, you could decide to not use this particular aspect of the syntax if it offends you, could you not? Those of us who have to support ie6 for the next three years, do not have that luxury.
If we're just proposing new ideas, suppose we create a new tag to link CSS3 documents to HTML documents? <stylesheet>, perhaps. Newer browsers know what to do with it, while older browsers ignore it. This is just off the top of my head, of course, I haven't thoroughly studied this problem.
I don't mean any personal offense, I just don't like the idea of putting code in comments.
For instance, with jQuery and a getStyleProperty helper[1]:
if (typeof getStyleProperty('borderRadius') != 'string') {
$('body').addClass('unsupported-border-radius');
}
... then in the CSS: body.unsupported-border-radius {
... alternate code goes here ...
}
[1] http://thinkweb2.com/projects/prototype/feature-testing-css-...1. It slows down rendering or causes a potentially huge reflow when the feature support classes are added.
2. The specificity of body.unsupported-border-radius .box is greater than the original rule, and this is going to cause issues with the rule ordering.
re: #2, a higher level of specificity acts like a ham-fisted override when the original rule you prefer can't be applied. that seems the right order of precedence to me.
EDIT: i see what you mean now. an @unsupported attribute as you describe acts like an either-or. the javascript solution i'm talking about cascades like a "this-and-also-this".
As much as people hate to hear it, the only real solution is some kind of browser-version tagging. If it wasn't for Microsoft's browsers supporting browser-specific conditional comments, we'd have a much harder time writing standards-compliant web pages that work the same for every browser.
It's a good approach - target only supported features through CSS inheritance. It's what I used to make my first commercial site with HTML5 and CSS3:
http://theprbootcamp.com (happening this Thursday in SF)
It was great, it made certain visual effects completely painless and degrades to a very similar but more square layout in IE6. It's not that you can't do rounded corners, dropshadows, multiple background images, gradients or have an IE6-friendly site design w/o it, it's just a giant time saver - I whipped together that site in less than a day - and the markup came out way cleaner.
No need to wait for the W3C to make a proposal or browser makers to integrate it, and you could remove the javascript if they ever come around.
<!--[if lte IE 7]>
<body class="ie67">
<![endif]-->
<!--[if !IE]>-->
<body>
<!--<![endif]-->
This allows me to target IE6/7 with the .ie67 class