asp.net.ph

Skip Navigation Links

background-attachment Attribute | backgroundAttachment Property

CSS Attributes Index   Color and Background Attributes


Sets or retrieves whether the background image scrolls with the object’s content or is fixed.

Syntax


CSS { background-attachment: 'scroll' | 'fixed' }
Script object.style.backgroundAttachment = sAttachment ]

Possible Values


scroll Background image scrolls with the content.
fixed Background image does not scroll with the content.

The property is read/write with a default value of scroll; this attribute is not inherited.

Remarks

This property may be set together with the other background properties using the background composite property.

Microsoft® Internet Explorer® 3.0 supports the background-attachment attribute, but only when it’s set through the background attribute.

Example

The following examples demonstrate how to set an element’s background-attachment style attribute so that it does not scroll with the text. Both methods yield the same effect.

The sample below defines a background-attachment style attribute in an embedded stylesheet.

<style>
body {
   background-image: url( sample.jpg );
   background-repeat: no-repeat;
   background-attachment: fixed }
</style>

The sample below uses inline event handlers to dynamically set an object’s backgroundAttachment property.

<body background="sample.jpg"
   onload="this.style.backgroundAttachment "fixed'">

The below example shows an alternative method to set the background-attachment attribute, using the composite background property. This method achieves the same result.

 Show me 

Applies To

BODY, currentStyle, HTML, runtimeStyle, style

See Also

background, background-color, background-image, background-position, background-repeat



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note