Older versions of Internet Explorer (IE) before version 9 do not support the background-size property:
If you are facing this compatibility issue, you'll need to employ a different technique to address it. Here is an article that explains some workarounds:
For example, take a look at this site I worked on previously, where the client required a background image that scaled with the screen size and changed during slides transitions. Please note that the code might be complex due to these specific requirements:
To understand how this was achieved, examine the CSS settings in
This website was also designed to be responsive, so there are multiple @media queries within the CSS file. There's a lot to explore, but here are some key aspects:
With a basic structure like this:
<html>
<head>
</head>
<body>
<div id="container">
<div id="header">
<!-- snip header stuff -->
</div>
<div id="main" role="main">
<!-- snip body stuff -->
</div>
<footer id="footer">
<!-- snip footer stuff -->
</footer>
<div id="background">
<div id="background-photo"><img id="bg_0" src="/Content/themes/base/images/index/bg-home-1200x933.jpg" class="opaque"></div>
</div>
<!-- snip js includes, per best practices,
located at the bottom of the page -->
</div>
</body>
</html>
Starting from line 316, the initial styles for the background container and its image are defined for smartphones ranging from 320px to 480px wide. At line 416, additional styles are set up for devices wider than 321px:
#background
{
left: 0;
min-height: 730px;
overflow: hidden;
position: fixed;
top: 0;
width: 100%;
... (truncated for brevity)
Note the setting for the container (#background) with 100% width and height, together with minimum height conditions, while the image inside has flexible width but a minimum width constraint. This design allows the image to scale proportionally based on the viewport dimensions. The usage of position:fixed ensures the background remains anchored, and z-index:-1 places it behind other content.
There are further adjustments for higher resolutions, but the fundamental setup remains unchanged. If you do not require fading/changing backgrounds, you can omit the opacity-related lines mentioned above as they make the image invisible.