XML technologies / CSS / CSS Cookbook / Hacks, workarounds and troubleshooting / Fixing background images in Internet Explorer 6 for Windows

(Excerpt from “CSS Kochbuch” by Christopher Schmitt)

Problem

You want to fix background images in Internet Explorer 6 for Windows on elements other than body.

Solution

Use the JavaScript code described below to force the desired effect. First, copy this code into your document:

<head>
  <script type="text/javascript" src="fixed.js"></script>
</head>

The source code for the file fixed.js is available on Andrew Clover’s website.

Discussion

According to CSS 2, a background image fixed with the property background-attachment should not move when the page scrolls. Unfortunately, this property does not work correctly in any version of Internet Explorer for Windows.

Andrew Clover’s remarkable JavaScript workaround solves this problem simply by adding the JavaScript link to the document. The code recalculates the viewport position during scrolling and adjusts the background image accordingly.

See also

The recipe Fixing the background image for more information on fixed background images, and the CSS 2 specification for the property background-attachment.

  

 

 

 

back to top