我正在構建一個SASS/Compass響應式網站,並且我包括視網膜圖標(使用生成的精靈)。我將這些圖標包含在我的.scss中,並帶有一個mixin。Internet Explorer 8使用視網膜像素媒體查詢
我的視網膜圖標混入:
// Retina icons
@mixin sprite-background($name, $xpos: 0px, $ypos: 0px, $xpos2x: $xpos, $ypos2x: $ypos, $size: image-width(sprite-file($icons, $name))) {
background-image: sprite-url($icons);
background-position: sprite-position($icons, $name, $xpos, $ypos);
background-repeat: no-repeat;
display: block;
@media all and ($pixel-ratio) {
@if (sprite-position($icons, $name) != sprite-position($icons2x, $name)) {
background-position: $xpos2x $ypos2x;
}
@include background-size($size auto);
background-image: sprite-url($icons2x);
}
}
變量:
$pixel-ratio: "-webkit-min-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), (min-device-pixel-ratio: 1.5";
用法:
.selector {
@include sprite-background(clock_small, 0px, 2px, 0px, -1013px, 45px);
}
我的問題是Internet Explorer 8在使用我的視網膜精靈作爲background-image
,並在background-size
上失敗。我知道IE8不支持background-size
,所以它被忽略,但這意味着我的圖標定位不正確。
使用JavaScript,你可以找到你的當前pixelratio:
alert(window.devicePixelRatio);
此提醒:undefined
在Internet Explorer中。 爲什麼我的「視網膜媒體查詢」接受undefined
作爲一個有效的數字,並執行其CSS?有沒有解決方法?
的可能重複[好方法作廢自適應網頁設計/媒體查詢的IE 8 - ?(HTTP://計算器。 com/questions/8914474/good-method-to-void-responsive-web-design-media-queries-for-ie-8) – cimmanon