和很多人一樣我真的很討厭的IE7開發和平時我用下面的方法:如何定位CSS的IE7標準
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="../res/styleie7.css">
<![endif]-->
這個目標的瀏覽器版本IE7,但不是IE7的文檔標準。
我需要一個使用IE(IE8,9,10)的更高版本但瀏覽器設置爲使用IE7標準的用戶的方法。有沒有辦法來檢測,而不是隻檢測瀏覽器版本?
和很多人一樣我真的很討厭的IE7開發和平時我用下面的方法:如何定位CSS的IE7標準
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="../res/styleie7.css">
<![endif]-->
這個目標的瀏覽器版本IE7,但不是IE7的文檔標準。
我需要一個使用IE(IE8,9,10)的更高版本但瀏覽器設置爲使用IE7標準的用戶的方法。有沒有辦法來檢測,而不是隻檢測瀏覽器版本?
我通常使用一個類屬性附加到HTML的方式:
<!--[if IE 7 ]><html class="no-js ie7" lang="en"><![endif]-->
<!--[if IE 8 ]><html class="no-js ie8" lang="en"><![endif]-->
<!--[if IE 9 ]><html class="no-js ie9" lang="en"><![endif]-->
<!--[if (gte IE 9)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"> <!--<![endif]-->
這樣,您就可以用IE前綴針對你的CSS,例如:
.ie7 .selector {
properties
}
這種方法適用例如,當我在IE7模式下運行IE10時
<!--[if lt IE 7]> <html lang="en" class="no-js ie lt-ie10 lt-ie9 lt-ie8 lt-ie7 ie6"> <![endif]-->
<!--[if IE 7]> <html lang="en" class="no-js ie lt-ie10 lt-ie9 lt-ie8 ie7"> <![endif]-->
<!--[if IE 8]> <html lang="en" class="no-js ie lt-ie10 lt-ie9 ie8"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="no-js ie lt-ie10 ie9"> <![endif]-->
<!--[if IE 10]> <html lang="en" class="no-js ie ie10"> <![endif]-->
<!--[if !IE]><!--><html lang="en" class="no-js"><!--<![endif]-->
將此代碼放在您的
現在你對IE7 CSS是
.ie7 .yourclass-or-id{
}
現在你對IE8的CSS是
.ie8 .yourclass-or-id{
}
現在你對IE9的CSS
.ie9 .yourclass-or-id{
}
現在你對IE10的CSS是
.ie10 .yourclass-or-id{
}
嗨。感謝您的回覆,但這似乎並不奏效。該腳本在加載時向html標籤添加一個類,並且我使用帶有ie7標準的Browsermode ie8,該類添加的是「ua-ie-8」。當我使用Browsermode ie7時,類是「ua-ie-7」。當我使用Browsermode ie8和ie8標準時,這些類與當我使用BrowserMode ie8和ie7標準時相同 – PaperThick
@PaperThick您能確認IE8標準的IE8顯示與IE7不同的useragent嗎? – SheetJS
我猜測,最後三個類添加了html標籤是定義瀏覽器和ie ie 8與ie7標準,他們是「UA - 即UA - ie - 8 UA - 即 - 8-0」和ie7與ie7標準是「ua - 即ua-ie-7 ua-ie-7-0」 – PaperThick
謝謝,但不能讓這對我來說 – PaperThick
工作在IE10例如,當你按下F12打開開發工具,然後將瀏覽器模式和文檔模式更改爲IE7,您是否看到應用於HTML元素的ie7類? –
不,當我運行例如Browsermode:ie8和ie7模式時,它並不適用,當我使用Browsermode ie7 – PaperThick