修复IE8的背景大小100%?

时间:2014-02-18 11:07:30

标签: css internet-explorer-8

我有以下css来获取背景图像以在一个部分内伸展100%。

.sectionclass {
  background: url('../img/bg.png') 50% 0 no-repeat fixed;
  background-size:100%;
  width: 100%;
  position: relative;
  line-height: 2;
  filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/bg.png', sizingMethod='scale');
}

它在IE的最新版本中运行良好,但是当我看IE7或IE8时,背景将不会全宽。解决这个问题最简单的方法是什么?

2 个答案:

答案 0 :(得分:8)

与CSS中与样式表所在目录相关的所有其他url()路径不同,src路径相对于使用样式表的页面。

例如,如果您的页面位于根目录中,并且样式表位于img目录旁边的自己的目录中(因此需要..),则需要更改src使其相对于根目录,如下所示:

  filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/img/bg.png', sizingMethod='scale')

答案 1 :(得分:1)

.yourclass {
    background:url(image-path) repeat fixed 100% 100%;
    background-attachment:fixed;
    background-size:100%;
    background:url(image-path) repeat fixed center center\9;

   /*IE 9*/
    background:url(image-path) repeat fixed top 100%; /* IE9 */
    background-attachment:fixed; /* IE9 */
    background-size:100%; /* IE9 */
}