aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/css/background-origin/index.html
blob: f9db364d8dee70d96299cd17ab45310f34a78a87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
---
title: background-origin
slug: Web/CSS/background-origin
translation_of: Web/CSS/background-origin
---
<div>{{CSSRef}}</div>

<h2 id="摘要">摘要</h2>

<p> <code>background-origin</code> 规定了指定背景图片{{cssxref("background-image")}} 属性的原点位置的背景相对区域.</p>

<p>注意:当使用 {{Cssxref("background-attachment")}} 为fixed时,该属性将被忽略不起作用。</p>

<div class="note">假如<span style="line-height: 1.5;">{{cssxref("background")}}简写中没有设置该值,那么在 background 简写值后指定</span><span style="font-family: courier new,andale mono,monospace; line-height: 1.5;">background-origin,那么后面的值就会覆盖简写值,其实说白了,就是后出现的值会覆盖前面的值。</span></div>

<p>{{cssinfo}}</p>

<h2 id="语法">语法</h2>

<pre class="twopartsyntaxbox"><a href="/en-US/docs/CSS/Value_definition_syntax" title="CSS/Value_definition_syntax">Formal syntax</a>: {{csssyntax("background-origin")}}</pre>

<pre>background-origin: border-box
background-origin: padding-box
background-origin: content-box

background-origin: inherit
</pre>

<h3 id="属性值">属性值</h3>

<dl>
 <dt><code>border-box</code></dt>
 <dd>背景图片的摆放以border区域为参考</dd>
 <dt><code>padding-box</code></dt>
 <dd>背景图片的摆放以padding区域为参考</dd>
 <dt><code>content-box</code></dt>
 <dd>背景图片的摆放以content区域为参考</dd>
 <dt>
 <h3 id="形式化语法" style="font-size: 1.71428571428571rem;">形式化语法</h3>
 <a class="syntaxbox-help icon-only" href="https://developer.mozilla.org/docs/Web/CSS/Value_definition_syntax" lang="en">How to read CSS syntax.</a>

 {{csssyntax("background-origin")}}
 </dt>
</dl>

<h2 id="例子">例子</h2>

<pre class="brush: css"> .example {
   border: 10px double;
   padding: 10px;
   background: url('image.jpg');
   background-position: center left;
   /* 背景将在内容区padding内部填充 */
   background-origin: content-box;
}
</pre>

<pre class="brush: css">#example2 {
    border: 4px solid black;
    padding: 10px;
    background: url('image.gif');
    background-repeat: no-repeat;
    background-origin: border-box;
 }</pre>

<pre class="brush:css; highlight:[4];">div {
  background-image: url('logo.jpg'), url('mainback.png');
  background-position: top right, 0px 0px;
  background-origin: content-box, padding-box;
}</pre>

<h2 id="规范">规范</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> </td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</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="相关文献">相关文献</h2>

<ul>
 <li><a href="https://www.cnblogs.com/shytong/p/5077129.html">【CSS3】background-origin和background-clip的区别</a></li>
</ul>