css background-size cover in internet explorer 7 [duplicate]

百般思念 提交于 2019-11-28 07:34:38

Using Modernizr you can discover what the user's browser is capable of.

Install Modernizr by linking it in your header

<script src="http://www.modernizr.com/downloads/modernizr-latest.js"></script>

And in your HTML tag,

<html class="no-js">

Using CSS you can style your page as the browser supports it - Check the documentation for what detection is supported. In this case, we want the background-size class

In your CSS file - For browsers without background-size (AKA just IE)

.no-background-size #image{
background-image: url(lol.png);
min-height: 100%;
min-width: 100%;
}

and this for browsers that do:

.background-size #image{
background-image: url(lol.png);
background-size: cover;
}

Using this method is more standards compliant, because in the future tags such as min-height: 100% could become unused.

pasx

Check this post for an answer:

How do I make background-size work in IE?

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

Works perfectly in IE8

Give your image a class of streched (or whatever else) and in your css put this :

img.stretched {
 min-height: 100%;
 min-width: 1024px;
 width: 100%;
 height: auto;
 position: fixed;
 top: 0;
 left: 0;
}

Be sure to put your img tag right below the <body> tag.

I've written a plugin for this:

https://github.com/aramkocharyan/CSS-Background-Size-jQuery-Plugin

<div style="width: 400px; height: 300px;">
    <img class="background-size-cover" src="apple.jpg" />
</div>

<script>
$(document).ready(function() {
    $('.background-size-cover').bgdSize('cover');
});
</script>

This works for me with IE7

http://kimili.com/journal/the-flexible-scalable-background-image-redux

You may need to install the IE9.js library from here (works with many versions of IE)

http://code.google.com/p/ie7-js/

Two ideas: 1. I'm currently trying to see if this filter helps:

AlphaImageLoader

  1. If background-size is not possible in IE, perhaps you would have to make your background-picture contain two images. The first image would have to be placed in a way, so it automatically displays correctly in IE without having to define background-size. For all other browsers you can use background-size and position to push the 2nd image into correct position. Trying this now...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!