Proposal: version at-rule

In a perfect world stylesheets would degrade nicely if a particular rule 
or selector was not supported by a browser. In the real world some rules 
build upon each others, sometimes older rules build on newer ones to be 
interpreted even.

A way to circumvent this problem would be identifying the minimum 
version that needs to be supported in order to process the stylesheet.
There are three ways I can think of:

1. The <link/> element in HTML or <?xml-stylesheet ?> PI in XML

<link href="mystyle.css" rel="stylesheet" type="text/css;version=3.0"/>
or
<?xml-stylesheet href="mystyle.css" type="text/css;version=3.0"?>
or
<link href="mystyle.css" rel="stylesheet" type="text/css" 
xml:css-version="3.0"/>
or
<?xml-stylesheet href="mystyle.css" type="text/css" version="3.0"?>

Where the third one is less preferable because it would require another 
XML attribute and the last one requires a change to the xml-stylesheet PI.
However this option allows the compatibility of the stylesheet to be 
determined before the actual sheet has been read by the browser.


2. An at-rule statement in the stylesheet

@version 3.0;

This would be placed somewhere at the beginning of the stylesheet (maybe 
even the first line) and determine the minimum version for the entire 
sheet. If a browser wouldn't meet this requirement, the stylesheet would 
be ignored.


3. An at-rule selector in the stylesheet

@version 3.0 {
     /* ... */
}

This would be the most favorable option in my opinion as it allows 
certain rules to be grouped and only applied if the browser meets the 
requirement. One could provide another expression like

@version "< 3.0" {
     /* ... */
}

in order to provide alternative content to browsers which have a lower 
version number. "3.0" would therefore mean "3.0 and higher", whereas "< 
3.0" would mean "lower than 3.0".

This selector might however conflict with the @media rule as, to my 
understanding, at-rules should not be contained within eachother.

Having the bracket syntax already, we could even have something along 
the lines of

@if[css-version >= 3.0] {
     /* ... */
}
@else {
     /* ... */
}

which would be inspired by the syntax of most bracket based programming 
languages.


While none of these ways would abandon the need of CSS-hacks, they would 
help preventing further need for even more ridiculous CSS-hacks than 
those we are using now (with CSS 2.1).


Yours,

Alan Plum

Received on Tuesday, 16 March 2004 12:19:20 UTC