【发布时间】:2014-05-17 05:05:10
【问题描述】:
我有一个奇怪的问题,即 IE8 似乎没有使用导入的 CSS 呈现我的背景图像。
由于 IE8 的问题和缺乏对许多 CSS3 元素的支持,我不得不使用条件逻辑来为我的网站内容加载特定的样式表。我正在使用 MVC4,我的 _Layout 页面在标题中有以下内容:
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<!--[if lt IE 9]>
<link href="@Url.Content("~/Content/DeprecatedSite.css")" rel="stylesheet" type="text/css" />
<![endif]-->
<!--[if gt IE 8]>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<style type="text/css">
.gradient {
filter:none;
}
</style>
<![endif]-->
在我的 deprecated.css 文件中,我有以下内容:
#main {
background:url('/Images/iecollage.png');
background-repeat:no-repeat;
width:100px;
}
在我的 site.css 中,我有相同 ID 标记的类似代码:
#main {
background:url('/Images/collage.png');
background-repeat:no-repeat;
background-size:920px;
width:100px;
}
我不得不使用 2 个不同大小的图像和属性定义来纠正浏览器解释标记的方式。我正在使用 IE8 和 Chrome 比较结果。
当我启动网站时,主页会反映相应的相应图像并按预期呈现所有内容。
当我导航到位于主目录之外的另一个页面时,就会出现我的问题(如果这确实对问题有任何影响)。
该页面具有以下内嵌代码:
<div id="spotlight" style="position:relative;left:-50px; top:2px; height:820px;margin: 0;width:650px;">
在我的 Site.css 文件中,ID 的样式如下:
#spotlight {
background:url('/Images/orange_spotlights3.jpg');
background-repeat:no-repeat;
-khtml-opacity:.60;
-moz-opacity:.60;
-ms-filter:"alpha(opacity=80)";
filter:alpha(opacity=80);
filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0.6);
opacity:.60;
width:100px;
}
在 Deprecated.css 中的样式是:
#spotlight {
background:url('/Images/orange_spotlights3.jpg') no-repeat;
}
在 Chrome 中,样式从导入的样式表中加载。但在 IE8 中,我得到了一个应该加载图像的空白区域。
我注意到的古怪行为是,如果我要从 Site.css 文件中删除以下行,那么 Chrome 和 IE8 都会渲染图像,但我会失去 Chrome 中的透明效果,这并不是分离不同样式表的 ID。
-ms-filter:"alpha(opacity=80)";
filter:alpha(opacity=80);
filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0.6);
opacity:.60;
好像这 2 个样式表会混淆浏览器或其他东西。
任何解释将不胜感激。
就目前而言,我正在考虑完全取消对 IE8 的任何支持,因为尝试创建 2 个不同的适应来呈现元素会变得非常麻烦。
【问题讨论】:
标签: css google-chrome internet-explorer-8