PIE.htc : CSS3 for everyone, even Internet Explorer !

Every single HTML developer knows that it’s really hard to make CSS styles to give the same render in every Internet browser ! Each browser has its own specifications : Chrome has webkit-, Safari does not, Firefox adds -moz … and IE 6/7/8 has nothing !

The IE solution : PIE.htc

The solution I give here has been developed to support CSS3 over IE platforms. To do so, we use a CSS functionality of IE to execute JavaScript, which will recreate CSS3 styles.

Demo on css3pie.com

Installation

You just have to add a single line to your CSS style to make it work with IE.

  1. <style type="text/css">
  2. .rounded-corner5
  3. {
  4.   -webkit-border-radius: 5px; /* Chrome */
  5.   border-radius: 5px; /* CSS3 */
  6.   -moz-border-radius: 5px; /* Mozilla */
  7.   behavior: url(PIE.htc); /* Internet Explorer */
  8. }
  9. </style>

Usage example

This is a div object with rounded corners, without using CSS3

Troubleshooting : a few rules to follow

There are two main issues you will/might face off :

  1. Mime-type : by default under linux, the .htc file is recognized as text/html, but should have text/x-component mime to be considered by IE. Some solutions, depending on what you can do on your server : change server /etc/mime.types configuration file to add the correct mime type, add the line AddType text/x-component .htc to your global apache/local .htaccess configuration, or create a PHP file that will override de default mime using header('Content-type: text/x-component').
  2. Domain, path and rights : the CSS line will work only if the .htc file is on the same domain than the HTML web page. Moreover, CSS3 rules using url() argument with relative paths might be misunderstood.

French version : CSS3 sous Internet Explorer 6, 7 et 8 avec PIE.htc

This entry was posted in Web technologies and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>