background-attachment property
Specifies whether the background-image should scroll with the contents of the object or not.
With this property you have control over how the background image behaves when the contents of the element are scrolled
(stays in a fixed position, or scrolls with the contents, as it normally does).
When a fixed value is used with background-position, the position is relative to the client window of the browser. For that reason, a fixed value is used for the body tag most of the cases.
JavaScript page for this property: backgroundAttachment. You can find other example(s) there. |
Possible values:
One of the following values:
Background image stays fixed. | |||||||
Takes the value of this property from the computed style of the parent element. | |||||||
Default. Background image scrolls with the contents of the object. |
Default: scroll.
Example HTML code 1:
This example illustrates the use of the background-attachment property:
|
||||
<head> <style> .fixed { background-image: url("bg.jpg"); background-repeat: repeat; background-attachment: fixed; overflow: scroll; width: 120px; height: 80px; } .scroll { background-image: url("bg.jpg"); background-repeat: repeat; background-attachment: scroll; overflow: scroll; width: 120px; height: 80px; } </style> </head> <body> <div class="fixed"> Scroll the contents of the page. The background image will stay in a fixed position. </div> <div class="scroll"> Scroll the contents of the page. The background image will scroll. </div> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by tags:
a, abbr, acronym, address, b, bdo, big, blink, blockQuote, body, button, caption, center, cite, code, col, colGroup, dd, del, dfn, dir, div, dl, dt, em, fieldSet, font, form, frame, frameSet, H1, H2, H3, H4, H5, H6, hr, html, i, iframe, img, input:button, input:checkbox, input:file, input:image, input:password, input:radio, input:range, input:reset, input:search, input:submit, input:text, ins, isIndex, kbd, label, legend, li, listing, marquee, menu, nobr, ol, p, plainText, pre, q, rt, ruby, s, samp, select, small, span, strike, strong, sub, sup, table, tBody, td, textArea, tFoot, th, tHead, tr, tt, u, ul, var, xmp
Related pages:
background
background-color
background-image
background-position
background-position-x
background-position-y
background-repeat
background-color
background-image
background-position
background-position-x
background-position-y
background-repeat
External links:
background-attachment (MSDN)
background-attachment (Mozilla Developer Center)
background-attachment (Safari Reference Library)
background-attachment (W3C)
background-attachment (Mozilla Developer Center)
background-attachment (Safari Reference Library)
background-attachment (W3C)
User Contributed Comments