aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/css/background-position-x/index.html
blob: 64aad74b28d038dbf1796f7520490d33988cccf9 (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
---
title: background-position-x
slug: Web/CSS/background-position-x
tags:
  - CSS
  - CSS Background
  - CSS Property
translation_of: Web/CSS/background-position-x
---
<div>{{CSSRef}}</div>

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

<p><strong><code>background-position-x</code></strong> CSS 属性设置水平方向的位置,与每个背景图片等位置层设置属性 {{cssxref("background-origin")}}相关。更多信息请查看{{cssxref("background-position")}}属性,这个用的比较普遍。</p>

<div class="note"><strong>注意:</strong>这个属性的值会被后面声明的属性覆盖掉,如{{cssxref("background")}}{{cssxref("background-position")}}等简写的属性。</div>

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

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

<pre class="brush: css">/* Keyword values */
background-position-x: left;
background-position-x: center;
background-position-x: right;

/* &lt;percentage&gt; values */
background-position-x: 25%;

/* &lt;length&gt; values */
background-position-x: 0px;
background-position-x: 1cm;
background-position-x: 8em;

/* side-relative values */
background-position-x: right 3px;
background-position-x: left 25%;

/* Multiple values */
background-position-x: 0px, center;

/* Global values */
background-position-x: inherit;
background-position-x: initial;
background-position-x: unset;
</pre>

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

<dl>
 <dt><code>left</code></dt>
 <dd>在位置层上相对于左边的位置。</dd>
 <dt><code>center</code></dt>
 <dd>在位置层上相对于中间点的位置。</dd>
 <dt><code>right</code></dt>
 <dd>在位置层上相对于右边的位置。</dd>
 <dt><code>&lt;length&gt;</code></dt>
 <dd>{{cssxref("&lt;length&gt;")}}值是定义相对于位置层边缘的距离,边缘默认为左边。</dd>
 <dt><code>&lt;percentage&gt;</code></dt>
 <dd>{{cssxref("&lt;percentage&gt;")}}值是定义相对于位置层边缘的距离百分比,边缘默认为左边。</dd>
</dl>

<h3 id="正规语法">正规语法</h3>

{{csssyntax}}

<h2 id="Specifications" name="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('CSS4 Backgrounds', '#background-position-longhands', 'background-position-x')}}</td>
   <td>{{Spec2('CSS4 Backgrounds')}}</td>
   <td>Initial specification of longhand sub properties of {{cssxref("background-position")}}  to match longstanding implementations.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility" name="Browser_compatibility">兼容性</h2>

<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>

<p>{{Compat("css/properties/background-position-x", "background-position-x")}}</p>

<h2 id="See_also" name="See_also">更多</h2>

<ul>
 <li>{{cssxref("background-position")}}</li>
 <li>{{cssxref("background-position-y")}}</li>
 <li>{{cssxref("background-position-inline")}}</li>
 <li>{{cssxref("background-position-block")}}</li>
 <li><a href="/en-US/docs/CSS/Multiple_backgrounds" title="CSS/Multiple backgrounds">Multiple backgrounds</a></li>
</ul>