mozilla

Revision 356623 of background-origin

  • Revision slug: CSS/background-origin
  • Revision title: background-origin
  • Revision id: 356623
  • Created:
  • Creator: ethertank
  • Is current revision? No
  • Comment highlight ...etc.

Revision Content

{{CSSRef}}

Summary

The background-origin CSS property determines the background positioning area, that is the position of the origin of an image specified using the {{cssxref("background-image")}} CSS property.

Note that background-origin is ignored when {{Cssxref("background-attachment")}} is fixed.

If the value of this property is not set in a {{cssxref("background")}} shorthand property that is applied to the element after the background-origin CSS property, the value of this property is then reset to its initial value by the shorthand property.
  • {{Xref_cssinitial}} {{cssinitial("background-origin")}}
  • Applies to all elements
  • {{Xref_cssinherited}} no
  • Media {{Xref_cssvisual}}
  • {{Xref_csscomputed}} as specified

Syntax

Formal syntax: {{csssyntax("background-origin")}}

Values

border-box
The background extends to the outside edge of the border (but underneath the border in z-ordering).
padding-box
No background is drawn below the border (background extends to the outside edge of the padding).
content-box
The background is painted within (clipped to) the content box.

Examples

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

Specifications

Specification Status Comment
{{SpecName('CSS3 Backgrounds', '#the-background-origin', 'background-origin')}} {{Spec2('CSS3 Backgrounds')}}  

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 [3] {{CompatGeckoDesktop("2.0")}} [1] 9.0 [2] 10.5 3.0 (522) [3]
content-box 1.0 [3] {{CompatGeckoDesktop("2.0")}} [1] 9.0 [2] {{CompatNo}} 3.0 (522) [3]
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
content-box {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

[1] Gecko supported, from version 1.1 to version 1.9.2, which corresponds to Firefox 1.0 to 3.6 included, a different, and prefixed, syntax: -moz-background-origin: padding | border.

[2] Internet Explorer up to version 7 behaves as if there was a background-origin: border-box; Internet Explorer 8 behaves as if it were background-origin: padding-box; which is the regular default value.

[3] Webkit also supports the prefixed version of this proprietary, and in that case, in addition to the current keywords, the alternative synonyms: padding, border, and content.

[4] Konqueror 3.5.4 supports -khtml-background-origin.

See also

  • {{CSS_Reference:Background}}

Revision Source

<div>{{CSSRef}}</div>
<h2 id="Summary">Summary</h2>
<p>The <code>background-origin</code> CSS property determines the background positioning area, that is the position of the origin of an image specified using the {{cssxref("background-image")}} CSS property.</p>
<p>Note that <code>background-origin</code> is ignored when {{Cssxref("background-attachment")}} is <code><code>fixed</code></code>.</p>
<div class="note">
  If the value of this property is not set in a {{cssxref("background")}} shorthand property that is applied to the element after the <code>background-origin</code> CSS property, the value of this property is then reset to its initial value by the shorthand property.</div>
<ul class="cssprop">
  <li><dfn>{{Xref_cssinitial}}</dfn> {{cssinitial("background-origin")}}</li>
  <li><dfn>Applies to</dfn> all elements</li>
  <li><dfn>{{Xref_cssinherited}}</dfn> no</li>
  <li><dfn>Media</dfn> {{Xref_cssvisual}}</li>
  <li><dfn>{{Xref_csscomputed}}</dfn> as specified</li>
</ul>
<h2 id="Syntax">Syntax</h2>
<pre class="syntaxbox">
<a href="/en-US/docs/CSS/Value_definition_syntax" title="CSS/Value_definition_syntax">Formal syntax</a>: {{csssyntax("background-origin")}}</pre>
<h3 id="Values">Values</h3>
<dl>
  <dt><code>border-box</code></dt>
  <dd>The background extends to the outside edge of the border (but underneath the border in z-ordering).</dd>
  <dt><code>padding-box</code></dt>
  <dd>No background is drawn below the border (background extends to the outside edge of the padding).</dd>
  <dt><code>content-box</code></dt>
  <dd>The background is painted within (clipped to) the content box.</dd>
</dl>
<h2 id="Examples">Examples</h2>
<pre class="brush:css; highlight:[7];">
 .example {
   border: 10px double;
   padding: 10px;
   background: url('image.jpg');
   background-position: center left;
   /* The background will be inside the padding */ 
   background-origin: content-box;
}
</pre>
<pre class="brush:css; highlight:[4];">
div {
  background-image: url('mainback.png'), url('logo.jpg');
  background-position: 0px 0px, top right;
  background-origin: padding-box, content-box;
}
</pre>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
  <thead>
    <tr>
      <th scope="col">Specification</th>
      <th scope="col">Status</th>
      <th scope="col">Comment</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>{{SpecName('CSS3 Backgrounds', '#the-background-origin', 'background-origin')}}</td>
      <td>{{Spec2('CSS3 Backgrounds')}}</td>
      <td>&nbsp;</td>
    </tr>
  </tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<div>{{CompatibilityTable}}</div>
<div id="compat-desktop">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Chrome</th>
        <th>Firefox (Gecko)</th>
        <th>Internet Explorer</th>
        <th>Opera</th>
        <th>Safari</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>1.0 [3]</td>
        <td>{{CompatGeckoDesktop("2.0")}} [1]</td>
        <td>9.0 [2]</td>
        <td>10.5</td>
        <td>3.0 (522) [3]</td>
      </tr>
      <tr>
        <td><code>content-box</code></td>
        <td>1.0 [3]</td>
        <td>{{CompatGeckoDesktop("2.0")}} [1]</td>
        <td>9.0 [2]</td>
        <td>{{CompatNo}}</td>
        <td>3.0 (522) [3]</td>
      </tr>
    </tbody>
  </table>
</div>
<div id="compat-mobile">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Android</th>
        <th>Firefox Mobile (Gecko)</th>
        <th>IE Phone</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
      </tr>
      <tr>
        <td><code>content-box</code></td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
      </tr>
    </tbody>
  </table>
</div>
<p>[1] Gecko supported, from version 1.1 to version 1.9.2, which corresponds to Firefox 1.0 to 3.6 included, a different, and prefixed, syntax: <code>-moz-background-origin: padding | border</code>.</p>
<p>[2] Internet Explorer up to version 7 behaves as if there was a <code>background-origin: border-box;</code> Internet Explorer 8 behaves as if it were <code>background-origin: padding-box;</code> which is the regular default value.</p>
<p>[3] Webkit also supports the prefixed version of this proprietary, and in that case, in addition to the current keywords, the alternative synonyms: <code>padding</code>, <code>border</code>, and <code>content</code>.</p>
<p>[4] Konqueror 3.5.4 supports<code> -khtml-background-origin</code>.</p>
<h2 id="See_also">See also</h2>
<ul>
  <li>{{CSS_Reference:Background}}</li>
</ul>
Revert to this revision