当我在@media中替换背景图像时,IE9 +中不再显示背景图像。它在FF,Safari和Chrome中完美无瑕。我尝试了几个旁路,但似乎是由这些线下降(见下文)。有人提出建议吗?
CODE
<div class="feature">
<ul class="feature-list">
<li class="nav-boat"><a href="/pages/disclaimer.php" ></a></li>
<li class="nav-camper"><a href="#"></a></li>
<li class="nav-tools"><a href="#"></a></li>
<li class="nav-cleaner"><a href="#"></a></li>
<li class="nav-motorcycle"><a href="#"></a></li>
<li class="nav-car"><a href="#"></a></li>
<li class="nav-warehouse"><a href="#"></a></li>
<li class="nav-office"><a href="#"></a></li>
</ul>
<div class="clear"></div>
</div>
CSS下方
.feature {
width:920px;
margin:30px auto;
height:500px;
}
.feature-list {
list-style: none;
}
.feature-list li {
width:185px;
height:185px;
margin-top:40px;
border:2px solid #4d4d4d;
margin-left:33px;
}
.feature-list li a {
text-decoration: none;
float: left;
}
.nav-camper {
background: url(/images/camper-icon-sm.gif) center center no-repeat;
}
.nav-camper:hover {
background-image: url(/images/camper-icon-hover-sm.gif);
}
.nav-boat {
background: url(../images/boat-icon-sm.gif) center center no-repeat;
}
.nav-boat:hover {
background-image: url(../images/boat-icon-hover-sm.gif);
}
.nav-tools {
background: url(../images/tools-icon-sm.gif) center center no-repeat;
}
.nav-tools:hover {
background-image: url(../images/tools-icon-hover-sm.gif);
}
.nav-cleaner {
background: url(../images/cleaner-icon-sm.gif) center center no-repeat;
}
.nav-cleaner:hover {
background-image: url(../images/cleaner-icon-hover-sm.gif);
}
.nav-motorcycle {
background: url(../images/motorcycle-icon-sm.gif) center center no-repeat;
}
.nav-motorcycle:hover {
background-image: url(../images/motorcycle-icon-hover-sm.gif);
}
.nav-car {
background: url(../images/car-icon-sm.gif) center center no-repeat;
}
.nav-car:hover {
background-image: url(../images/car-icon-hover-sm.gif);
}
.nav-warehouse {
background: url(../images/warehouse-icon-sm.gif) center center no-repeat;
}
.nav-warehouse:hover {
background-image: url(../images/warehouse-icon-hover-sm.gif);
}
.nav-office {
background: url(../images/office-icon-sm.gif) center center no-repeat;
}
.nav-office:hover {
background-image: url(../images/office-icon-hover-sm.gif);
}
@media query。
@media screen and (max-width: 769px) {
.feature-list li {
width:120px;
height:120px;
}
.feature ul li a {
width: 120px;
height: 120px;
}
.divider {
display:none;
}
.nav-camper {
background: url(../images/camper-icon-xs.gif) center center no-repeat;
}
.nav-camper:hover {
background-image: url(../images/camper-icon-hover-xs.gif);
}
.nav-boat {
background: url(../images/boat-icon-xs.gif) center center no-repeat;
}
.nav-boat:hover {
background-image: url(../images/boat-icon-hover-xs.gif);
}
.nav-tools {
background: url(../images/tools-icon-xs.gif) center center no-repeat;
}
.nav-tools:hover {
background-image: url(../images/tools-icon-hover-xs.gif);
}
.nav-cleaner {
background: url(../images/cleaner-icon-xs.gif) center center no-repeat;
}
.nav-cleaner:hover {
background-image: url(../images/cleaner-icon-hover-xs.gif);
}
.nav-motorcycle {
background: url(../images/motorcycle-icon-xs.gif) center center no-repeat;
}
.nav-motorcycle:hover {
background-image: url(../images/motorcycle-icon-hover-xs.gif);
}
.nav-car {
background: url(../images/car-icon-xs.gif) center center no-repeat;
}
.nav-car:hover {
background-image: url(../images/car-icon-hover-xs.gif);
}
.nav-warehouse {
background: url(../images/warehouse-icon-xs.gif) center center no-repeat;
}
.nav-warehouse:hover {
background-image: url(../images/warehouse-icon-hover-xs.gif);
}
.nav-office {
background: url(../images/office-icon-xs.gif) center center no-repeat;
}
.nav-office:hover {
background-image: url(../images/office-icon-hover-xs.gif);
}
}
答案 0 :(得分:0)
IE9不支持媒体查询在文本文件中添加JS代码并将其保存为css-media-query-ie.js名称并将其添加到目录,然后在html页面的头部添加以下标记。
<强> HTML 强>
<head>
<!--[if lt IE 9]>
<script type="text/javascript" src="css-media-query-ie.js"></script>
<![endif]-->
</head>
<强> CSS-媒体查询ie.js 强>
/*!
* CSS Media Queries for IE later than 9.0
* http://ghita.org/tipoftheday/css-media-queries-for-ie
* Copyright 2011, Serban Ghita
* Released under the GPL Licenses.
*/
var detectAndUseStylesheet = function(){
var currentWidth = screen.width,
// currentWidth = parseInt(document.documentElement.clientWidth),
//currentWidth = 320,
cssLinks = document.getElementsByTagName('link'),
_check = new RegExp(currentWidth, 'i'),
foundResolution = false,
allSupportedResolutions = [];
for(ii in cssLinks){
if(cssLinks[ii].href){
if(cssLinks[ii].id){
allSupportedResolutions.push(cssLinks[ii].id.match(/[0-9]+/i)[0]);
if(cssLinks[ii].id.match(_check)){
document.getElementById('stylesheet-'+currentWidth).removeAttribute('media');
foundResolution = true;
}
}
}
}
// Fallback if resolution is not found.
if(!foundResolution){
for(ii in allSupportedResolutions){
if(currentWidth<allSupportedResolutions[ii]){
document.getElementById('stylesheet-'+allSupportedResolutions[ii]).removeAttribute('media');
break;
}
}
}
}
window.attachEvent('onload', detectAndUseStylesheet);
<强>参考强> see more