Quackit Logo
HTML
CSS
Scripting
Database
Hosting
Design
XML

Print Version

HTML Fixed Background

This article provides HTML fixed background code - code for fixing the background image of an HTML element so that it doesn't scroll when its containing block scrolls.

To fix the position of a background image, use the CSS background-attachment property.

Example code:

<div style="background-image:url(/pix/smile.gif);
		background-repeat:repeat;
		background-attachment:fixed;
		overflow:scroll;
		width:200px;
		height:100px;">
</div>

This results in:

HTML fixed background code is generated by applying the CSS background-attachment property against an HTML element. When the box scrolls, the background image stays fixed in the same position.

Shorthand Code

You can use the CSS background tag to set all the background properties at once. Therefore, using the previous code example, we could rewrite it to this:

<div style="background:url(/pix/smile.gif) repeat fixed;
		overflow:scroll;
		width:200px;
		height:100px;">
HTML fixed background code is generated by applying the
CSS background-attachment property against an HTML element.
When the box scrolls, the background image stays fixed
in the same position.
</div>
HTML fixed background code is generated by applying the CSS background-attachment property against an HTML element. When the box scrolls, the background image stays fixed in the same position.

Enjoy this website?

  • Share
  • Add this page to your Favorites
  • Link to this page (copy/paste into your own website or blog):
  • Link to Quackit using one of these banner ads.
  • Help support Quackit by making a donation

Oh, and thank you for supporting Quackit!

© Copyright 2000 - 2010 Quackit.com