Wednesday, July 1st, 2009
Modernizr: HTML5 and CSS3 detection
Modernizr is a new library that detects various HTML5 and CSS3 features and lets you know so you can use them:

Writing conditional CSS with Modernizr
Now, once your page loads, Modernizr will run and go through all of its tests. It will automatically add all the classes to the <body> element of the page, and these classes will be along the lines of body.feature or body.no-feature, with the former indicating that the current browser supports that specific feature and the latter indicating that the browser does not support the feature.
Additionally, it will create a new JavaScript object in the global scope, called Modernizr. This object will contain properties for each of the features that Modernizr detects for, and their value will be set to TRUE or FALSE depending on the browser's support for it.
What you can do from this point on is write pseudo-IF/ELSE statements in your CSS. Let's look at an example from the Modernizr.com site itself:
CSS:
.cssgradients #main { background: -webkit-gradient(linear, left 0, right bottom, from(rgba(255,255,255, .82)), to(rgba(255,255,255, 0))) 0 0 no-repeat; }In the above example, we're doing an "IF" condition in CSS: IF the browser supports both CSS gradients, THEN apply this background property to the #main element (instead of the original background property).
Writing conditional JavaScript with Modernizr
When leveraging Modernizr in your JavaScript, it's as straight-forward as it can be to do IF-conditions based on what the browser currently supports:
JAVASCRIPT:
if (Modernizr.cssgradients) { // perform some actions you only want to // execute if the browser supports gradients }
We are seeing a growth in these kinds of tools and shims to get HTML5 features into developers hands. Another great site to help is the new HTML5 Doctor.












Psst: your second code example lists it as CSS but it’s JavaScript inside it. :-)
I like the idea, but what sort of performance hit are you going to see in IE7/IE6 by including this on your site? Especially since you’re changing the tag’s class attribute, which will cause reflow if you add clientside on page load.
You’re supposed to embed it directly after the BODY element, precisely to avoid any reflow / restyling issues.
It’s only doing one real DOM operation, and that’s added the series of classes to the BODY element. The whole thing is only 16kb uncompressed (6kb compressed) and typically runs in less than 20 ms on modern machines. It’ll be a bit longer in IE6 because it has such a slow JavaScript engine, but it’s still very much within acceptable ranges.
Slashdotted? o_O
Modernizr is hosted on Google AppEngine, which suffered a system-wide down period this morning. It’s back up now, though.
You could do something very similar using a custom processor with CSSugar.
You have no idea the hacks you have to produce to be able to write both CSS 3 and 2.1 compatible stylesheets that don’t mess with each other.
This little script could really save a lot of time and headache.
Thank you!
I’ve made a similar open source lib called “Supports.js” (http://dev.netzgesta.de/).
Whenever you need to know if a CSS property is supported and what it’s DOM name is!
It allows you to check style features and also referable style values.
It depends not on a fixed list of items to check and therefor it is forward compatible.
It’s only about 2600 bytes and without the heading comments less than 2048 bytes.
With the changing trend of the world, wedding apart from white,Princess Strapless Satin Evening Dress ivory, beige and other traditional colors,are also increasingly popular in recent years, ghetto prom dressespink wedding package,gothic prom dresses such as pink, pink orange, baby blue, purple night, light green and light silver-gray, very soft and pleasing to wedding hair accessoriesthe eye; if you have the courage to try, dark green, purplish red, deep purple, decorated in pink wedding dress, the formation of rich colors,the dress, the effect is very special;Sash Lace Satin Flower Girl Dress, laden with flour colored silk flowers, butterflies, in order to add color.wedding dressIn fact, the wedding is the color of lesser importance, the most important prerequisite is to match the bride’s complexion. Oriental deep and yellowish color, wearing white Mermaid Satin Organdie Wedding Dress,will appear dull, wearing ivory would be more harmonious and natural, baby blue, wedding accessoriespurple night can not be coordinated with the yellow, but pink orange, light green with yellowish color match. As for the skin and rosy, or bronze skin, wearing white will look great, wedding dress
A wedding dresses is always
expensive. Every couple will agree on this.When you are planning for
your wedding, you will probably find that every item can be very
expensive. This is especially true when it comes to the wedding dress.
You may think that there is no way for you to get a Wedding gown dresswhich is
elegant and at the same time cheap. However, I can tell you that there
are some ways to save money on this item.
So, the question here is how to make your white wedding dressinexpensive.
In fact, one thing you need to understand is that it is totally
possible for you to find a cheap
wedding dress which is also elegant and beautiful. You do not need
to sacrifice the quality just because you will need to search for cheap wedding gowns items.
As a matter of fact, one of the ways to get a bridal gowns is to wear the one
your mother wore when she got married. The point here is that you will
be wearing a bridal dresses
item and it will certainly be very stylish.