CSS does not have conditional statements because it is not a programming language like Javascript. Although, I believe that there may be some conditional statement in CSS for CSS.
You will need to rely on JavaScript to get some conditional test case for CSS.
Meaning, you cannot directly detect CSS support.
However, CSS has a "trick" due to its "cascading" nature, but it can only be used when looking for old code with newer code for the same style.
This sounds funny, here are a few examples:
-moz-border-radius: 6px; -o-border-radius: 6px; -webkit-border-radius: 6px; -ms-border-radius: 6px; border-radius: 6px;
In browsers that support official CSS, this will be the style indicated on line 5. In older versions of, say, Firefox, line 1 will be applied and line 2-5 will be ignored because they are unknown.
Another (and possibly best) example might be:
background-color: #AAA; background-color: rgba(0, 0, 0, 0.5);
This code will give the background a gray color, while new browsers will give it a black color with 50% transparency, overriding the old color.
Hope this helps.
Hooray!
- Update -
I just came across something that might help. In Aaron Gustafson’s book “Responsive Web Design,” he mentions how CSS will ignore the whole rule if a given browser / renderer does not support this selector.
With the concept above, if you can find a selector that was not implemented in the old version but is available in the newer version, you can do something like this:
.sprite { background-image: url(sprite90x38.png); } [[ selector that is supported by newer browser/OS ]], .sprite { background-image: url(sprite180x76.png); background-size: 90px auto; }
The idea is that for "old" browsers you can download the old PNG, but for a newer browser, it will load a larger PNG and resize the background.
The only thing I will worry about is that this causes the supporting browsers to load both images, but apply them.
And it still requires finding an unsupported selector in one version of the other. Quicksmode.com can help you find it:
http://www.quirksmode.org/css/contents.html
- UPDATE 2 -
I put this in the comments, but I will add it here, as this may help. I spent some time trying to figure out which version of iOS 3.1.3 browser is supported, and therefore which selectors can be used with the above trick.
I found this Apple developer site: http://developer.apple.com/library/safari/#documentation/appleapplications/reference/SafariCSSRef/Articles/StandardCSSProperties.html
If you do a page search (ctr + f) for the background, it shows that iOS 1+ supports the proprietary version:
-webkit-background-size: length -webkit-background-size: length_x length_y
This may be a possible solution. If you add this to the real, you can provide backward compatibility.
-webkit-background-size: length background-size: length
Hope this helps find alternative solutions, since the original question of running a conditional test to see if a rule is supported is not possible in CSS right now.