aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/css/background-attachment/index.html
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/css/background-attachment/index.html
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/css/background-attachment/index.html')
-rw-r--r--files/zh-cn/web/css/background-attachment/index.html149
1 files changed, 149 insertions, 0 deletions
diff --git a/files/zh-cn/web/css/background-attachment/index.html b/files/zh-cn/web/css/background-attachment/index.html
new file mode 100644
index 0000000000..4247605e0c
--- /dev/null
+++ b/files/zh-cn/web/css/background-attachment/index.html
@@ -0,0 +1,149 @@
+---
+title: background-attachment
+slug: Web/CSS/background-attachment
+tags:
+ - CSS Background
+ - CSS Property
+ - CSS_参考
+ - Reference
+translation_of: Web/CSS/background-attachment
+---
+<div>{{CSSRef}}</div>
+
+<p><strong><code>background-attachment</code></strong> <a href="https://developer.mozilla.org/en-US/docs/CSS">CSS</a> 属性决定背景图像的位置是在{{glossary("视口")}}内固定,或者随着包含它的区块滚动。</p>
+
+<div>{{EmbedInteractiveExample("pages/css/background-attachment.html")}}</div>
+
+<p class="hidden">该交互式示例网页的源码存储在GitHub中,如果你想为该网页项目做点贡献的话,请进此链接 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> 并给我们一个请求加入的回复。</p>
+
+<h2 id="Syntax" name="Syntax">语法</h2>
+
+<pre class="brush: css no-line-numbers language-css"><code class="language-css"><span class="comment token">/* 关键 属性值 */</span>
+<span class="property token">background-attachment</span><span class="punctuation token">:</span> scroll<span class="punctuation token">;</span>
+<span class="property token">background-attachment</span><span class="punctuation token">:</span> fixed<span class="punctuation token">;</span>
+<span class="property token">background-attachment</span><span class="punctuation token">:</span> local<span class="punctuation token">;</span>
+
+<span class="comment token">/* 全局 属性值 */</span>
+<span class="property token">background-attachment</span><span class="punctuation token">:</span> inherit<span class="punctuation token">;</span>
+<span class="property token">background-attachment</span><span class="punctuation token">:</span> initial<span class="punctuation token">;</span>
+<span class="property token">background-attachment</span><span class="punctuation token">:</span> unset<span class="punctuation token">;</span></code></pre>
+
+<h3 id="取值" style="font-size: 1.71428571428571rem;">取值</h3>
+
+<dl>
+ <dt><code>fixed</code></dt>
+ <dd>此关键属性值表示背景相对于视口固定。即使一个元素拥有滚动机制,背景也不会随着元素的内容滚动。</dd>
+ <dt><code>local</code></dt>
+ <dd>此关键属性值表示背景相对于元素的内容固定。如果一个元素拥有滚动机制,背景将会随着元素的内容滚动, 并且背景的绘制区域和定位区域是相对于可滚动的区域而不是包含他们的边框。</dd>
+ <dt><code>scroll</code></dt>
+ <dd>此关键属性值表示背景相对于元素本身固定, 而不是随着它的内容滚动(对元素边框是有效的)。</dd>
+ <dt>
+ <h3 id="标准语法" style="font-size: 1.71428571428571rem;">标准语法</h3>
+ </dt>
+</dl>
+
+<pre class="syntaxbox">{{csssyntax}}</pre>
+
+<h2 id="例子">例子</h2>
+
+<h3 id="简单的例子">简单的例子</h3>
+
+<h4 id="CSS样式表">CSS样式表</h4>
+
+<pre class="brush:css; highlight:[3];">p {
+ background-image: url("https://mdn.mozillademos.org/files/12057/starsolid.gif");
+ background-attachment: fixed;
+}
+</pre>
+
+<h4 id="HTML源码">HTML源码</h4>
+
+<pre class="brush: html">&lt;p&gt;
+ There were doors all round the hall, but they were all locked; and when
+ Alice had been all the way down one side and up the other, trying every
+ door, she walked sadly down the middle, wondering how she was ever to
+ get out again.
+&lt;/p&gt;</pre>
+
+<h4 id="效果">效果</h4>
+
+<p>{{EmbedLiveSample("简单的例子")}}</p>
+
+<h3 id="多背景图支持">多背景图支持</h3>
+
+<p>此属性支持多张背景图片。你可以用逗号分隔来为每一张背景图片指定不同的<code>&lt;attachment&gt;属性值。</code>每一张背景图片顺序对应相应的 attachment 属性。</p>
+
+<h4 id="CSS样式表_2">CSS样式表</h4>
+
+<pre class="brush:css; highlight:[3];">p {
+ background-image: url("https://mdn.mozillademos.org/files/12057/starsolid.gif"), url("https://mdn.mozillademos.org/files/12059/startransparent.gif");
+ background-attachment: fixed, scroll;
+ background-repeat: no-repeat, repeat-y;
+}</pre>
+
+<h4 id="HTML源码_2">HTML源码</h4>
+
+<pre class="brush: html">&lt;p&gt;
+ There were doors all round the hall, but they were all locked; and when
+ Alice had been all the way down one side and up the other, trying every
+ door, she walked sadly down the middle, wondering how she was ever to
+ get out again.
+
+ Suddenly she came upon a little three-legged table, all made of solid
+ glass; there was nothing on it except a tiny golden key, and Alice's
+ first thought was that it might belong to one of the doors of the hall;
+ but, alas! either the locks were too large, or the key was too small,
+ but at any rate it would not open any of them. However, on the second
+ time round, she came upon a low curtain she had not noticed before, and
+ behind it was a little door about fifteen inches high: she tried the
+ little golden key in the lock, and to her great delight it fitted!
+&lt;/p&gt;</pre>
+
+<h4 id="效果_2">效果</h4>
+
+<p>{{EmbedLiveSample("多背景图支持")}}</p>
+
+<h2 id="规范" style="margin-bottom: 20px; font-size: 2.14285714285714rem;">规范</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">CSS版本</th>
+ <th scope="col">推荐状态</th>
+ <th scope="col">点评</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName('CSS3 Backgrounds', '#the-background-attachment', 'background-attachment')}}</td>
+ <td>{{Spec2('CSS3 Backgrounds')}}</td>
+ <td>该简单上手的属性已经支持更多的背景图和局部(local)值</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('CSS2.1', 'colors.html#propdef-background-attachment', 'background-attachment')}}</td>
+ <td>{{Spec2('CSS2.1')}}</td>
+ <td>无明显变化</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('CSS1', '#background-attachment', 'background-attachment')}}</td>
+ <td>{{Spec2('CSS1')}}</td>
+ <td>无明显变化</td>
+ </tr>
+ </tbody>
+</table>
+
+<p>{{cssinfo}}</p>
+
+<h2 id="浏览器兼容性" style="margin-bottom: 20px; font-size: 2.14285714285714rem;">浏览器兼容性</h2>
+
+<div class="hidden">本页中的兼容性表格是由结构化数据生成的。如果你想对数据提供补充,请查看此链接 <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> 并给我们一个请求补充的回复。</div>
+
+<p>{{Compat("css.properties.background-attachment")}}</p>
+
+<div id="compat-mobile"></div>
+
+<h2 id="参见" style="margin-bottom: 20px; font-size: 2.14285714285714rem;">参见</h2>
+
+<ul>
+ <li><a href="https://developer.mozilla.org/en-US/docs/CSS/Multiple_backgrounds">更多背景图</a></li>
+</ul>