May
6

Using CSS3 in older browsers

By Sam  //  All browsers, CSS 3.0  //  No Comments

If you want to use CSS3 and HTML5 in older browsers there are a few ways of doing it, but today we are going to focus on something called Modernizr.

Modernizr adds various classes to theĀ <html> element which allow you to target specific browser functionality using your stylesheet.

The simplest example is just as the Modernizr site says;

.multiplebgs div p {
  /* properties for browsers that
     support multiple backgrounds */
}
.no-multiplebgs div p {
  /* optional fallback properties
     for browsers that don't */
}

In the example above, the Modernizr JavaScript code will detect if the browser your visitor is using supports multiple backgrounds or not. If it is one of the browsers that does not, Modernizr appends class=”no-multiplegbs” to your <html> element.

Then, it’s up to you to decide what should happen on your site. You can control what users of these older browsers see using the stylesheet and help your site to degrade gracefully.

Leave a comment

Sponsored links