css區分ie8/ie9/ie10/ie11 chrome firefox的代碼


以下是幾個主要瀏覽器的css  hack匯總:

現有css樣式為:

.class{
   color:red;
}

判斷IE8以上的瀏覽器才執行的代碼
/*
IE8+ */ .class{ color:red\0; } 
/* IE8、9 */
.class{
    color:red\8\9\0;
}
/* IE9 */
.class{
    color:red\9\0;
}

注意,\8\0的寫法是錯誤的,不能試圖這樣hack IE8。上述代碼沒有對IE10和IE11分別hack(好像沒有對這兩個瀏覽器單獨hack的寫法),那么IE10和IE11使用的就是IE8+那個樣式

/* Chrome */
@media screen and (-webkit-min-device-pixel-ratio:0) {
    .class{
       color:red;
    }
}
/* Firefox */
@-moz-document url-prefix() {
    .class{
        color:red;
    }
}

另外,還可以這樣hack其他瀏覽器

/* Chrome 和 opera */
@media all and (min-width:0){
    .class{
        color:red;
    }
}
/* IE9+ */
@media all and (min-width:0) {
    .class{
        color:red;
    }
}
/* IE10+ */
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none)  {
    .class{
        color:red;
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM