background-origin

  • Revision slug: CSS/background-origin
  • Revision title: background-origin
  • Revision id: 28789
  • Created:
  • Creator: Jürgen Jeka
  • Is current revision? No
  • Comment 30 words added

Revision Content

{{ CSSRef() }}

Summary

The background-origin CSS property determines the background positioning area (the origin of a background-image).
background-origin does not apply when {{ Cssxref("background-attachment") }} is fixed.
-moz-background-origin is supported up to Gecko version 1.9.2 (Firefox 3.6).{{ warning("To support both, older and newer versions of Gecko (Firefox), you have to add both properties in the stylesheet. See examples.") }}

This property is reset to its initial value by the {{ Cssxref("background") }} shorthand property.

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

Syntax

/* since Gecko 1.9.3 (Firefox 4.0) */
background-origin: [padding-box | border-box | content-box][, [border-box | padding-box | content-box]]*

/* older versions (multiple backgrounds since Gecko 1.9.2 / Firefox 3.6) */
-moz-background-origin: [padding | border | content][, [border | padding | content]]*

Values

padding-box {{ Fx_minversion_inline("4") }}
padding (Firefox 1.0-3.6)
Default value. The background position is relative to the padding. (For single boxes "0 0" is the upper left corner of the padding edge, "100% 100%" is the lower right corner.)
border-box {{ Fx_minversion_inline("4") }}
border (Firefox 1.0-3.6)
The background position is relative to the border, so the image can go behind the border.
content-box {{ Fx_minversion_inline("4") }}
content (Firefox 1.0-3.6)
The background position is relative to the content.

Examples

 .example {
   border: 10px double;
   padding: 10px;
   background: url('image.jpg');
   background-position: center left;
   /* The background will be inside the padding */       
   -moz-background-origin: content;          /* Firefox 1.0-3.6 */
   -webkit-background-origin: content-box;   /* Safari, Chrome */
           background-origin: content-box;   /* Firefox 4.0+ */
}
div {
  background-image: url('mainback.png'), url('logo.jpg');
  background-position: 0px 0px, top right;
  -moz-background-origin: padding, content;
  -webkit-background-origin: padding-box, content;
          background-origin: padding-box, content-box;
}

Browser compatibility

Browser Lowest version Support of
Internet Explorer --- --- [*]
Firefox (Gecko) 1.0-3.6 (1.2-1.9.2) -moz-background-origin:  padding | border | content
4.0 (1.9.3) background-origin:  padding-box | border-box | content-box
Opera 10.5 background-origin:  padding-box | border-box | content-box
Safari (WebKit) 3.0 (522) -webkit-background-origin:  padding | border | content
-webkit-background-origin:  padding-box | border-box | content-box
  • [*]  IE up to version 7 defaults to  background-origin: border;
  • IE 8 default behaviour is  background-origin: padding;
  • Konqueror 3.5.4 supports -khtml-background-origin.

Specifications

See also

  • {{ cssxref("-moz-background-size") }}
  • {{ CSS_Reference:Background() }}

{{ languages( { "fr": "fr/CSS/-moz-background-origin", "ja": "ja/CSS/-moz-background-origin", "pl": "pl/CSS/-moz-background-origin" } ) }}

Revision Source

<p>{{ CSSRef() }}</p>
<h3>Summary</h3>
<p>The<code> background-origin </code>CSS property determines the background positioning area (the origin of a background-image).<br>
<code>background-origin </code>does not apply when {{ Cssxref("background-attachment") }} is<code> <code>fixed</code></code>.<br>
<code> -moz-background-origin </code>is supported up to Gecko version 1.9.2 (Firefox 3.6).{{ warning("To support both, older and newer versions of Gecko (Firefox), you have to add both properties in the stylesheet. See examples.") }}</p>
<p>This property is reset to its initial value by the {{ Cssxref("background") }} shorthand property.</p>
<ul> <li>{{ Xref_cssinitial() }}: {{ Cssxref("padding") }}</li> <li>Applies to: all elements</li> <li>{{ Xref_cssinherited() }}: no</li> <li>Media: {{ Xref_cssvisual() }}</li> <li>{{ Xref_csscomputed() }}: as specified<code><br> </code></li>
</ul><h3>Syntax</h3>
<pre>/* since Gecko 1.9.3 (Firefox 4.0) */
background-origin: [<code>padding-box | border-box | conten</code><code>t-box</code>][, [<code>border-box | padding-box | conten</code><code>t-box</code>]]*

/* older versions (multiple backgrounds since Gecko 1.9.2 / Firefox 3.6) */
-moz-background-origin: [<code>padding | border | conten</code><code>t</code>][, [<code>border | padding | conten</code><code>t</code>]]*
</pre>
<h3>Values</h3>
<dl> <dt> </dt><dt>padding-box {{ Fx_minversion_inline("4") }}<br> padding <small>(Firefox 1.0-3.6)</small></dt> <dd>Default value. The background position is relative to the padding. (For single boxes "<code>0 0</code>" is the upper left corner of the padding edge, "<code>100% 100%</code>" is the lower right corner.)</dd> <dt>border-box {{ Fx_minversion_inline("4") }}<br> border <small>(Firefox 1.0-3.6)</small></dt> <dd>The background position is relative to the border, so the image can go behind the border.</dd> <dt>content-box {{ Fx_minversion_inline("4") }}<br> content <small>(Firefox 1.0-3.6)</small></dt> <dd>The background position is relative to the content.</dd>
</dl>
<h3>Examples</h3>
<pre> .example {
   border: 10px double;
   padding: 10px;
   background: url('image.jpg');
   background-position: center left;
   /* The background will be inside the padding */       
   -moz-background-origin: content;          /* Firefox 1.0-3.6 */
   -webkit-background-origin: content-box;   /* Safari, Chrome */
           background-origin: content-box;   /* Firefox 4.0+ */
}
</pre>
<pre>div {
  background-image: url('mainback.png'), url('logo.jpg');
  background-position: 0px 0px, top right;
  -moz-background-origin: padding, content;
  -webkit-background-origin: padding-box, content;
          background-origin: padding-box, content-box;
}</pre>
<h3>Browser compatibility</h3>
<table class="standard-table"> <tbody> <tr> <th>Browser</th> <th>Lowest version</th> <th>Support of</th> </tr> <tr> <td>Internet Explorer</td> <td>---</td> <td>--- [*]</td> </tr> <tr> <td rowspan="2">Firefox (Gecko)</td> <td>1.0-3.6 (1.2-1.9.2)</td> <td><code>-moz-background-origin:  padding | border | content</code></td> </tr> <tr> <td>4.0 (1.9.3)</td> <td><code>background-origin:  padding-box | border-box | content-box</code></td> </tr> <tr> <td>Opera</td> <td>10.5</td> <td><code>background-origin:  padding-box | border-box | content-box</code></td> </tr> <tr> <td>Safari (WebKit)</td> <td>3.0 (522)</td> <td><code>-webkit-background-origin:  padding | border | content </code><br> <code>-webkit-background-origin:  padding-box | border-box | content-box</code></td> </tr> </tbody>
</table>
<ul> <li>[*]  IE up to version 7 defaults to <code> background-origin: border;</code></li> <li>IE 8 default behaviour is <code> background-origin: padding;</code><code><br> </code></li> <li>Konqueror 3.5.4 supports<code> -khtml-background-origin</code>.</li>
</ul>
<h3>Specifications</h3>
<ul> <li><a class="external" href="http://www.w3.org/TR/css3-background/#background-origin" title="http://www.w3.org/TR/css3-background/#background-origin">CSS 3 Background and borders #background-origin</a><br> Specifies the values<code> border-box | padding-box | content-box.</code></li>
</ul>
<h3>See also</h3>
<ul> <li>{{ cssxref("-moz-background-size") }}</li> <li>{{ CSS_Reference:Background() }}</li>
</ul>
<p>{{ languages( { "fr": "fr/CSS/-moz-background-origin", "ja": "ja/CSS/-moz-background-origin", "pl": "pl/CSS/-moz-background-origin" } ) }}</p>
Revert to this revision