Scale background image to fit ie8 window

本小妞迷上赌 提交于 2019-12-11 14:14:04

问题


I'm using a drupal 7 module to load in a background image but IE8 doesn't support css3 resizing.

background-image: url('image.jpg');
background-size: cover;

I can't easily load in the image using the usual methods such as putting it in a DIV or using the ms-filter alphaimageloader to load it.

A javascript solution is fine if this can't be done with just CSS that ie8 supports. (Something that also works for ie7 would be fantastic too, but ie8 is the priority).


回答1:


Add Full Size Background Image to Internet Explorer 8, and IE7

Since you can't easily place the background in your site using the usual methods, can you place an image within your code? If so, this solution might work. I used it to simulate a full-screen background for IE8 and IE7, and it works well.

Place the image right after the body tag in the html code. (You can probably place it elsewhere depending on your site structure, but you may have to add a z-index.) Next, the background in this example is wrapped in an IE Conditional Comment so only IE8 and below will see it. (Note: It's buggy in IE6, but you might be able to get it to work? If not, just adjust the Conditional Comment to include IE7 and IE8 only).

HTML Code

<!DOCTYPE html>
<head></head>
<body>
<!--[if lte IE 8]><img src="../path-to-your-image/your-photo.jpg" class="ie87-bg"><![endif]-->

CSS

.ie87-bg {
display:block;
position:fixed;
top:0;
left:0;
min-height:100%;
min-width:1024px;
width:100%;
height:auto;
margin:0;
padding:0;
}

You probably already know this, but here are 3 ways to target older versions of IE:

  1. JavaScript browser feature detection - mattstow.com/layout-engine.html
  2. Css Hacks - BrowserHacks.com
  3. IE Condtional Comments http://msdn.microsoft.com/en-us/library/ms537512%28VS.85%29.aspx

Helpful Tips: background-image:none; overwrites background-size: cover. The _ hack is one way to turn off the custom IE background in IE6 .ie87-bg {_display: none;}.

position:fixed; is buggy in mobile/touch screens. The default position:scroll; works well on touch. The background idea is from this tutorial - http://css-tricks.com/perfect-full-page-background-image/




回答2:


This works for me to stretch image on full window in IE8

http://css-tricks.com/perfect-full-page-background-image/



来源:https://stackoverflow.com/questions/19415191/scale-background-image-to-fit-ie8-window

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