Gets or sets how the background image is attached to the object within the document.
Syntax
CSS { background-attachment : sAttachment } Scripting [ sAttachment = ] object.style.backgroundAttachment
Possible Values
sAttachment String that specifies or receives one of the following values.
- scroll
- Default. Background image scrolls with the object as the document is scrolled.
fixed- Background image stays fixed within the viewable area of the object.
The property is read/write for all objects except the following, for which it is read-only: currentStyle. The property has a default value of scroll. The Cascading Style Sheets (CSS) attribute is not inherited.
DHTML expressions can be used in place of the preceding value(s). As of Internet Explorer 8, expressions are supported in IE7 Standards mode and IE5 (Quirks) mode only. For more information, see About Dynamic Properties and Defining Document Compatibility.
Remarks
This property can be set with the other background properties by using the background composite property.
Microsoft Internet Explorer 3.0 supports the background-attachment attribute, but only when it's set by using the background attribute.
In Internet Explorer 9, the background of a box can have multiple layers. The number of layers is determined by the number of comma-separated values in the background-image property. Each of the images is sized, positioned, and tiled according to the corresponding value in the other background properties ( background-attachment, background-clip, background-origin, background-position, background-repeat, and background-size). The first image in the list is the layer closest to the user, the next one is painted behind the first, and so on.
Examples
The following examples use the background-attachment attribute and the backgroundAttachment property to set the background to "fixed", so that the background does not scroll with the text.This example uses an inline style sheet to set the background to fixed.
<STYLE > BODY { background-attachment:fixed } </STYLE> </HEAD> <BODY background="some.jpg">Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/background-attachment.htm
This example uses inline scripting to set the background to fixed.
<BODY ID="oBdy" background="marble05.jpg" onload="oBdy.style.backgroundAttachment = 'fixed'">Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/backgroundAttachment.htm
Standards Information
This property is defined in Cascading Style Sheets (CSS), Level 1 (CSS1).
Applies To
A, ADDRESS, ARTICLE, ASIDE, B, BIG, BLOCKQUOTE, BODY, BUTTON, CAPTION, CENTER, CITE, CODE, COL, COLGROUP, CSSStyleDeclaration, currentStyle, CUSTOM, DD, defaults, DFN, DIR, DIV, DL, DT, EM, FIGCAPTION, FIGURE, FIELDSET, FOOTER, FORM, HEADER, HGROUP, hn, HTML, I, IFRAME, IMG, INPUT type=button, INPUT type=checkbox, INPUT type=file, INPUT type=image, INPUT type=password, INPUT type=radio, INPUT type=reset, INPUT type=submit, INPUT type=text, ISINDEX, KBD, LABEL, LAYOUTRECT, LEGEND, LI, LISTING, MARK, MARQUEE, MENU, NAV, OL, OPTION, P, PLAINTEXT, PRE, runtimeStyle, S, SAMP, SECTION, SMALL, SPAN, STRIKE, STRONG, style, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TR, TT, U, UL, VAR, XMP, CSSCurrentStyleDeclaration Constructor, CSSRuleStyleDeclaration Constructor, CSSStyleDeclaration Constructor
In
Internet Explorer 9, the background of a box can have multiple layers. The number of layers is determined by the number of comma-separated values in the