Tech Hive

Blog on Wordpress, Design, Usability, Accessibility and Standards

  • Content
  • Sidebar
  • Footer
  • « The Basics of Accessibility
  • Appending the title of the post in Read More links for Wordpress »

The Great IE 6 Hack

Leave a response | Trackback |
Tags: css, htc, IE, IE hack

As a designer, the biggest problems that I have with IE are the PNG transparency problem and the :hover pseudo class is not working unless it’s used in the a element.

Thanks for HTC which is only understood by IE 5.5 and above browsers — I’ve found some handy “hacks” to work around these 2 limitations on the browser designers/programmers’ love to hate.

Note: calling it in CSS will make your CSS file invalid even though it’s a part of CSS property lists, I tested it against CSS 1, 2, 2.1 and 3 (just to be sure) so… CSS valid-freaks sorry… Maybe it remained to be just a part of the draft?

PNG Transparency

I have to admit that I haven’t really looked that hard for PNG transparency hacks, sure you can use PNG 8 but, isn’t it just a “PNGized” GIF? Anyway, if you’re certain that you won’t be using your image on plain backgrounds and your background does not have patterns on them then PNG 8 will be a good solution.

So, while I was looking for a hack to make PNG work on IE 6, I came across IE PNG Fix of Twinhelix which is a good enough solution for me because it doesn’t complicate things for me and it also works on PNG backgrounds on CSS and images you have to insert into your HTML file. However, this being a “hack”, of course it has some limitations too.

The list is from the author, the ones that with emphasis are mine.

  • Can’t help IE versions prior to 5.5, sorry.
  • Users can’t right-click-save processed PNG images, they’ll save the blank GIF file if they try that. In some cases this might be a feature, not a bug…
  • The script detects the “.png” extension in image URLs. So if you have a CGI script that generates a PNG image, you may have to rewrite parts of the script, or just cache them as PNG files somewhere. Apparently, this is also an issue in RoR, I really don’t know why but the images will still not be transparent unless you specifically call the image using the <img> tag, so say goodbye to your <%= image_tag("path_to_file_here") %> way of calling images (unless it’s a JPG or GIF of course).
  • It’s most reliable on elements with non-’auto’ dimensions set. So, give images and other elements width/height values; ‘100%’, ‘10em’ and ‘200px’ and so on are all OK, otherwise, you will have a heart attack once you’ve seen it in IE, it’s transparent, yes but still, it is not pretty.
  • Background PNG images can’t be tiled. This is a limitation of the IE filter.
  • Similarly, padding and borders don’t indent the PNG image. An easy fix for this is wrapping your PNG images in container DIVs or similar.
  • There may be about a short time as soon as the image loads when images are not transparent, before the IE filter kicks in.

For it to work, all you have to do is create a blank transparent GIF file (it doesn’t matter what size it is) put the path to it in the htc file and call the htc by adding

* { behavior: URL(/path_to/iepngfix.htc) }

anywhere in your CSS file. Note that you can replace * with img or whatever element you want. Then voila! PNG transparency has been achieved.

Applying :hover pseudo class for whatever element in IE 6

As I’ve said before, another shortcoming of IE 6 is that it only applies the :hover pseudo class on the a element so it’s really hard to create a hover state for menu items using the sliding door technique unless all you have to do is change the menu item’s link color. Unless you love cutting images for specific menu items or your item’s width is fixed and don’t care what it’ll look like once you have increased the font size, then I guess you need not worry about it.

Anyway, this time, I need not look so hard because of whatever:hover yey! All you have to do is put the htc file anywhere in your site, call it in your CSS using the behavior property again like so –

* { behavior: URL(/path_to/csshover.htc) }

(again you can change * to whatever element you want) and voila! You can apply the :hover pseudo class to whatever element that you want and you can be absolutely certain that it will be reflected in IE 6. Lovely. :)

Is there a hack for IE 6 that you know? Please do share. :)

Update (April 28, 2008): Joni buzzed me earlier to ask if maybe adding the behavior property in a stylesheet that’s meant only for IE will make your stylesheet valid. I tried it at Last Leaf and it did! So… now you can make your site valid even though you’re using htc. I can’t believe I failed to test that when I’ve been using IE conditionals for more than a year already! hehe Credit to Joni Ang, XHTML/CSS/Wordpress theme designer extraordinaire :) Also, if you’re using wordpress and you added htc within your theme’s folder, don’t forget to add the complete path to your blank.gif and htc, otherwise, it won’t work.

9 Responses to “The Great IE 6 Hack”

  1. Joni April 22, 2008 at 9:09 am

    You’re a genius.

  2. Mae April 22, 2008 at 12:24 pm

    I wish! hehe Mas magaling ka pa rin :D

  3. mk April 24, 2008 at 12:01 am

    well I’m a validity freak but I do know of another method to solve the PNG problem in IE. It’s a javascript called “supersleight” (just google it I’m sure it will POP out) but unfortunately I don’t know any fixes to the :hover pseudo class

  4. Mae April 24, 2008 at 10:02 am

    Hey Mk,

    Thanks for that! :D I’m not a ig fan of javascript hehe but I’ll take a look at it :) I just wish that the behavior property becomes valid soon.. :)

  5. Joni April 28, 2008 at 2:55 pm

    YAY! I LAVETTTT! :)

  6. Mae April 28, 2008 at 3:22 pm

    @Joni I know, right? :D

  7. luis April 28, 2008 at 3:28 pm

    Apparently, this is also an issue in RoR, I really don’t know why but the images will still not be transparent unless you specifically call the image using the img tag, so say goodbye to your image_tag(”path_to_file_here”)

    The reason is that Rails (and other frameworks and CMSes) tend to append timestamps to the end of their images, e.g., /images/filename.png?1294850030, to help with browser-caching. Since the HTC hack looks at the last 4 characters of a filename to determine whether it’s a .PNG or not, the Rails-powered filenames become invisible to it. Apart from rewriting the regular-expressions that HTC uses to parse the DOM, I have no idea how one would go about fixing this without incurring a penalty in bandwidth. (Because your images would then not be cached properly, if at all.)

  8. Mae May 2, 2008 at 2:14 pm

    oh.. I think I remembered you explaining that to me before… darn goldfish memory hehe

  9. Good Web Design Tips May 26, 2008 at 8:41 am

    Your site looks great! I found your blog via Google while searching for good web design tips and your post regarding at IE 6 Hack | Tech Hive | Blog on Wordpress, Web Design, Accessibility, Standards and Usability looks very interesting to me. I have seen many other so-called sites and they have been far from good quality.Your site has all the key ingredients to pulling in visitors.

Leave a Reply

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

Pages

  • About the Author
  • Archives
  • Contact
  • Site Map

Post a job. Find one. authenticjobs.com
Come in, we're hiring

Full-time and freelance job opportunities available at Authentic Jobs:

Post a job and reach web professionals everywhere.

Archives

  • September 2008
  • August 2008
  • July 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • December 2007
  • November 2007
  • October 2007
  • September 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007

Categories

  • Accessibility
  • CSS Tips
  • Gmail
  • HTML
  • Online Finds
  • Online Tools
  • Tutorial
  • Updates
  • Usability
  • WordPress
  • Wordpress Themes
Sign up for PayPal and start accepting credit card payments instantly.

Tech Hive is proudly powered by WordPress
Spartan by Mae Paulino, a Filipina Web Designer