Code:
body { background-attachment: fixed !important; filter: progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr=#000000,endColorStr=#3d3c3c); }
Gradient does not stay fixed in IE8 but scrolls into a plain white background. Gradients stay fixed in Firefox and Chrome and scroll with the page.
Is there any way to have it fixed
in IE8 as well? I wasn't even aware this was an issue (can't find anything according to Google).
Edit: I created a test page with the code above (and quite a bit of Lorem Ipsum) and the background was fixed like it should be. So it must be something in my layout.
To keep your background fixed, scroll, or local in CSS, we have to use the background-attachment property. Background-attachment: This property is used in CSS to set a background image as fixed or scroll. The default value of this property is scroll.
You can combine a background-image and CSS3 gradient on the same element by using several backgrounds. In our example below, we set the height and width of our <div> and add a background. Then, we set the background image fallback using the “url” value of the background-image property.
The background-attachment CSS property sets whether a background image's position is fixed within the viewport, or scrolls with its containing block.
CSS gradients allow us to display smooth transitions between two or more colours. They can be added on top of the background image by simply combining the background-image URL and gradient properties.
It looks like all you're missing is to set a height on the body. Adding this style works for me in IE 8:
html, body {height: 100%}
So, using your style from your fiddle, it would look like this:
html, body {height: 100%}
body {
background-attachment: fixed !important;
filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0, startColorstr=#000000, endColorstr=#ffffff);
}
And this is what the cross-browser version would look like:
html, body {height: 100%}
body {
background-attachment: fixed !important;
filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0, startColorstr=#000000, endColorstr=#ffffff);
background-image: -moz-linear-gradient(center top -90deg, #000000, #ffffff);
background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#000000), to(#ffffff));
}
Obviously, you could put the IE specific code elsewhere and load it conditionally, etc.
This tested fine in IE 8, Firefox 3.6, Chrome 9 & Safari 5 (Webkit) but does not work in Opera. For Opera, SVG or actual background image?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With