I have a background image. I am stretching it so that it fits the entire page.But it is working in browsers other than IE.But if I use background-size, it is working in IE9. But I want it to work in IE8. How to do this? Thanks in advance.
In other browsers and in IE9:
In IE8:
You can find the difference at the bottom of the page. Here is my code:
body, html{
height:100%;
padding:0;
margin:0;
}
body.BodyBackground {
margin: 0px;
background: url(../images/common/header/Background_color.png);
background-repeat:repeat-x;
background-attachment:fixed;
background-position:top center;
height: 100%;
width: 100%;
border: 0;
background-size:contain;
display:inline-block;
background-color: transparent;
}
div.content{
height:100%;
width:97%;
background-color: rgb(255, 255, 255);
margin: 0px 25px 25px 25px;
height:470px;
background-position:center;
background-repeat:no-repeat;
background-attachment:fixed;
}
CSS3 is going to implement a background-size attribute. But it isn't supported in IE<9.
If you want to scale a background gradient, you may use the img element because it is scaling. Instead of using a background to display the PNG, you now use an img element, and set the width and the height to 100%.
I think that this is what you want:
The markup:
IE8 does not support
background-size
property.You have the following options:
Use a background graphic that doesn't need stretching.
Provide IE8 with a different background image (or no background image at all)
[edit] See my blog post on the subject for more info on how to achieve this in pure CSS with no browser hacks.
Ignore the problem and let IE8 users see a slightly broken site.
Use a polyfill script like CSS3Pie to add the
background-size
feature to IE8.If you really want to use
background-size
, and you really need to support IE8, then the last of those options is probably the best one for you.Whilst like other answers state
background-size
is not supported is true. There are other ways this can be achieved.You can use the following to achieve stretched backgrounds in old IE.
Other sizing options for
sizingMethod
:It is important you do not use this on the
html
orbody
tag. Instead, create afixed
position div with 100% width and height.