full size background image in ie8

放肆的年华 提交于 2019-12-08 13:59:26

Try this

<div id="bg">
  <img src="images/bg.jpg" alt="">
</div>

#bg {
  position: fixed; 
  top: -50%; 
  left: -50%; 
  width: 200%; 
  height: 200%;
}
#bg img {
  position: absolute; 
  top: 0; 
  left: 0; 
  right: 0; 
  bottom: 0; 
  margin: auto; 
  min-width: 50%;
  min-height: 50%;
}

I made a Sass Mixin if this help anyone:

@mixin background-cover($cover-image){
  background: url($cover-image) no-repeat center center;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  -ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='#{$cover-image}', sizingMethod='scale')";
  filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='#{$cover-image}', sizingMethod='scale');
}

Call it by using

@include background-cover('/images/foo.png');

I know this is late, but this answer may help someone else:

Download backgroundsize.min.htc and put it inside your project.

Now simply add these lines in your css:

.class_name{
    //your other properties
    background-size: cover;
    -ms-behavior: url(backgroundsize.min.htc);
}

NOTE: use the url according to your project setup.

Enjoy this simple solution. :)

I think generic tags should go after the browser-specific ones:

-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
 background-size: cover;

and also:

-ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../../images/bg.jpg', sizingMethod='scale')";
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../../images/bg.jpg', sizingMethod='scale');

Hope this works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!