Implementing a Full Size Background Image for Internet Explorer 8 and IE7
Struggling to add a full-size background image to your website on Internet Explorer 8 and IE7? Conventional methods may not work, but fear not! There is a workaround that involves embedding the image directly into your code. I successfully created a full-screen background using this solution.
To execute this method, simply insert the image right after the opening body tag in your HTML code. Although you may need to adjust the z-index depending on your site's structure, this approach ensures compatibility with IE8 and below by wrapping the background image in an IE Conditional Comment. (Note: While it may have some issues with IE6, tweaking the Conditional Comment to target only IE7 and IE8 should do the trick).
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;
}
In case you didn't already know, there are three ways to target older versions of IE:
- JavaScript browser feature detection - mattstow.com/layout-engine.html
- Css Hacks - BrowserHacks.com
- IE Conditional Comments http://msdn.microsoft.com/en-us/library/ms537512%28VS.85%29.aspx
Helpful Tips: Using background-image:none;
will override background-size: cover
. The _ hack can be used to disable the custom IE background in IE6 .ie87-bg {_display: none;}
.
position:fixed;
may not work well on mobile/touch screens. Consider using position:scroll;
as an alternative. This background concept is inspired by a tutorial found at http://css-tricks.com/perfect-full-page-background-image/