MDN may have intermittent access issues April 18 13:00 - April 19 01:00 UTC. See whistlepig.mozilla.org for all notifications.

mozilla

Revision 21268 of background-attachment

  • Revision slug: CSS/background-attachment
  • Revision title: background-attachment
  • Revision id: 21268
  • Created:
  • Creator: GreatS
  • Is current revision? No
  • Comment 8 words added, 1 words removed

Revision Content

{{ CSSRef() }}

Summary

If a {{ Cssxref("background-image") }} is specified, background-attachment determines whether that image's position is fixed within the viewport, or scrolls along with its containing block.

  • {{ Xref_cssinitial() }}: scroll
  • Applies to: all elements
  • {{ Xref_cssinherited() }}: no
  • Media: {{ Xref_cssvisual() }}
  • {{ Xref_csscomputed() }}: as specified

Syntax

background-attachment:  <attachment>[, <attachment>]*

Where:

<attachment>
scroll | fixed | local

{{ gecko_minversion_note("1.9.2", "Gecko 1.9.2 introduced support for multiple background images; prior to 1.9.2, only one <attachment> </attachment>value is supported.") }}

Values

scroll
If scroll is specified, the background image will scroll within the viewport along with the block the image is contained within.
fixed
If fixed is specified, the background image will not scroll with its containing element, instead remaining stationary within the viewport.
local
{{ unimplemented_inline() }} in Gecko (Firefox)

Examples

{{ CSSRefExampleLink("background-attachment") }}

body {
	background-image: url("images/cartooncat.png");
	background-attachment: fixed;
}

Multiple background image support

Gecko 1.9.2 supports multiple background images. You can specify a different <attachment> for each background, separated by commas:

body {
  background-image: url("img1.png"), url("img2.png");
  background-attachment: scroll, fixed;
} 

Each image is matched with the corresponding attachment type, from first specified to last.

Browser compatibility

Browser Lowest version Multiple backgrounds "local" value
Internet Explorer 4.0 --- ---
Firefox (Gecko) 1.0 (1.0) 3.6 (1.9.2) ---
Opera 3.5 10.5 10.5
Safari (WebKit) 1.0 (85) 1.3 (312) Implemented, v. unknown

Specifications

See also

{{ languages( { "de": "de/CSS/background-attachment", "es": "es/CSS/background-attachment", "fr": "fr/CSS/background-attachment", "it": "it/CSS/background-attachment", "pl": "pl/CSS/background-attachment" } ) }}

Revision Source

<p>{{ CSSRef() }}</p>
<h3>Summary</h3>
<p>If a {{ Cssxref("background-image") }} is specified, <code>background-attachment</code> determines whether that image's position is fixed within the viewport, or scrolls along with its containing block.</p>
<ul> <li>{{ Xref_cssinitial() }}: scroll</li> <li>Applies to: all elements</li> <li>{{ Xref_cssinherited() }}: no</li> <li>Media: {{ Xref_cssvisual() }}</li> <li>{{ Xref_csscomputed() }}: as specified</li>
</ul>
<h3>Syntax</h3>
<pre>background-attachment:  &lt;attachment&gt;[, &lt;attachment&gt;]*
</pre>
<p>Where:</p>
<dl> <dt>&lt;attachment&gt;</dt> <dd><code>scroll | fixed | local</code></dd>
</dl>
<p>{{ gecko_minversion_note("1.9.2", "Gecko 1.9.2 introduced support for multiple background images; prior to 1.9.2, only one <code><attachment> </attachment></code>value is supported.") }}</p>
<h3>Values</h3>
<dl> <dt>scroll</dt> <dd>If <code>scroll</code> is specified, the background image will scroll within the viewport along with the block the image is contained within.</dd> <dt>fixed</dt> <dd>If <code>fixed</code> is specified, the background image will not scroll with its containing element, instead remaining stationary within the viewport.</dd> <dt>local</dt> <dd>{{ unimplemented_inline() }} in Gecko (Firefox)</dd>
</dl>
<h3>Examples</h3>
<p>{{ CSSRefExampleLink("background-attachment") }}</p>
<pre>body {
	background-image: url("images/cartooncat.png");
	background-attachment: fixed;
}
</pre>
<h4>Multiple background image support</h4>
<p>Gecko 1.9.2 supports multiple background images. You can specify a different <code>&lt;attachment&gt;</code> for each background, separated by commas:</p>
<pre>body {
  background-image: url("img1.png"), url("img2.png");
  background-attachment: scroll, fixed;
} 
</pre>
<p>Each image is matched with the corresponding attachment type, from first specified to last.</p>
<h3>Browser compatibility</h3>
<table class="standard-table"> <tbody> <tr> <th>Browser</th> <th>Lowest version</th> <th>Multiple backgrounds</th> <th>"local" value</th> </tr> <tr> <td>Internet Explorer</td> <td>4.0</td> <td>---</td> <td>---</td> </tr> <tr> <td>Firefox (Gecko)</td> <td>1.0 (1.0)</td> <td>3.6 (1.9.2)</td> <td>---</td> </tr> <tr> <td>Opera</td> <td>3.5</td> <td>10.5</td> <td>10.5</td> </tr> <tr> <td>Safari (WebKit)</td> <td>1.0 (85)</td> <td>1.3 (312)</td> <td>Implemented, v. unknown</td> </tr> </tbody>
</table>
<h3>Specifications</h3>
<ul> <li><a class="external" href="http://www.w3.org/TR/CSS21/colors.html#propdef-background-attachment">CSS 2.1 Colors and Backgrounds #background-attachment</a></li> <li><a class="external" href="http://www.w3.org/TR/css3-background/#the-background-attachment" title="http://www.w3.org/TR/css3-background/#the-background-attachment">CSS 3 Backgrounds and Borders #background-attachment </a></li>
</ul>
<h3>See also</h3>
<ul> <li>{{ CSS_Reference:Background() }}</li> <li><a href="/en/CSS/Multiple_backgrounds" title="en/CSS/Multiple backgrounds">Multiple backgrounds</a></li> <li><a class=" external" href="http://www.quirksmode.org/css/background.html" title="http://www.quirksmode.org/css/background.html">Quirksmode background compatibility</a></li>
</ul>
<p>{{ languages( { "de": "de/CSS/background-attachment", "es": "es/CSS/background-attachment", "fr": "fr/CSS/background-attachment", "it": "it/CSS/background-attachment", "pl": "pl/CSS/background-attachment" } ) }}</p>
Revert to this revision