CSS hack for IE6 and IE7
Everyone know what a underscore hack is, but it fails in IE. Before getting into the Underscore hack, we need to know how it works,
If a property say height is prefixed with _ or – IE6 will assume that as a valid property but FF will ignore it, so for any IE6 specific style we can use _ or -. But in IE7 that bug was fixed, so if any property is followed by _ or -, IE7 will ignore it similar to Firefox.
Dont lose, still IE is not that robust, if you place a ‘*’ before the property, it considers, now that is something to smile about and thinking deeper. So if a property is prefixed by a *, it will be considered as a valid property, but we can a small problem here, even IE6 will take this as a valid one. So summing up everything we have
|
|
* |
_ or - |
|
Firefox |
Invalid |
Invalid |
|
IE6 |
Valid |
Valid |
|
IE7 |
Valid |
Invalid |
Analyzing the above table, if we want something specific to IE 7, then it should be prefixed with * and considering the fact that IE6 will also understand that, we must override that for IE6. We can override that with _ or – property. So here is the solution,
- Define a property for Firefox – normal manner
- Define the same property for IE7 with * Prefix
- Define the complementary property (margin left and margin right) for IE6
Deciding the complementary property needs some amount of logical input. So for example, for a margin issue, this is what we gona have.
- For Firefox, margin-right: 10px;
- For IE6, _margin-left: 8px;
- For IE7, *margin-right: 2px;
That is all we need to do. Now we will see the same in all the brwosers, this is pretty ugly hack, but we dont have a better solution
March 20, 2008 at 9:10 am
Thanks you very much for this hack !
March 24, 2008 at 3:18 pm
er
March 28, 2008 at 7:41 pm
thanks
March 28, 2008 at 7:43 pm
[...] hack for IE6 and IE7 « WEB2pointO CSS hack for IE6 and IE7 « WEB2pointO If a property say height is prefixed with _ or – IE6 will assume that as a valid property but FF [...]
April 21, 2008 at 5:07 am
Thanks!
May 30, 2008 at 7:17 am
thanks for sharing this hack with us
July 22, 2008 at 6:03 pm
Thank you for this simplified summary of the hacks!
July 28, 2008 at 3:29 pm
Thank you dear for this hack. I need this now.
October 20, 2008 at 6:13 pm
[...] When you need to tell Internet Explorer something slightly different from your normal CSS, use hacks specialized for IE6 and IE7. [...]
November 6, 2008 at 9:03 am
I try this one but it doesn’t work… please help
March 18, 2009 at 9:16 am
Thanks a Lot.. Very Simple to understand…
March 31, 2009 at 6:47 pm
OMG, thank you for this! Simple hack, and actually quite elegant. I thought I was going to lose my mind trying to accommodate both IE6 and IE7. M$ should be legally banned from publishing software because they have no clue and have caused immeasurable grief worldwide.
June 30, 2009 at 11:32 am
Thanks
July 31, 2009 at 4:56 am
Than you so much! It really works!
November 3, 2009 at 9:08 am
If we are using clasess…..We have to give the same class name with the hack for different browsers ???