aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/css/background-origin/index.html
blob: 683f22bc9ed130a2dd92e68c42d6b47ab4e77fee (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
---
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>

{{Compat("css.properties.background-origin")}}

<h2 id="相关文献">相关文献</h2>

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