區(qū)別不同瀏覽器CSS hack:區(qū)分IE6,IE7,IE8,firefox

字號:


    區(qū)別不同瀏覽器,CSS hack寫法,從網(wǎng)上看到很多文章,現(xiàn)總結一下,盡量全面一點,備查。
    注意下面介紹的這些hack寫法僅適用于XHTML1.0。如果沒有在HTML最前加上
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "> xmlns="">
    那么效果將不一樣!此外,這里所說的IE8,不是指IE8的兼容模式,因為IE8的兼容模式其實就是IE7。
    區(qū)別IE6、7與FF/IE8:
    background:blue;*background:orange;
    引用
    顯示效果:
    IE 6/7:orange
    FF/IE8:blue
    原理:FF/IE8不支持*開頭,而IE6/7都支持。
    區(qū)別IE6與IE7/IE8/FF:
    background:green;_background:blue;
    引用
    顯示效果:
    IE7/8/FF:green
    IE6:blue
    原理:IE6支持下劃線"_",IE7、8和firefox均不支持下劃線。
    區(qū)別FF/IE8和IE6/7:
    background:orange;+background:green;-background:blue;
    或者
    background:orange;*background:green!important;*background:blue;
    引用
    顯示效果:
    IE6:blue
    IE7:green
    FF/IE8:orange
    原理:IE6能識別-,IE7能識別+,IE8和FF都不能識別+和-
    IE8/FF都不識別*,IE7優(yōu)先識別!important,IE6不能識別!important。
    關于IE8的hacks:
    .test{
    color:#00f9;
    color:#00f9;
    }
    可同時區(qū)分IE8、IE7、IE6、Firefox的CSS hacks:
    .test{
    color:#000;
    color:#00f9;
    *color:#f00;
    _color:#0f0;
    }