aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/html/element/picture
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/html/element/picture
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/html/element/picture')
-rw-r--r--files/zh-cn/web/html/element/picture/index.html128
1 files changed, 128 insertions, 0 deletions
diff --git a/files/zh-cn/web/html/element/picture/index.html b/files/zh-cn/web/html/element/picture/index.html
new file mode 100644
index 0000000000..a9c9638a6f
--- /dev/null
+++ b/files/zh-cn/web/html/element/picture/index.html
@@ -0,0 +1,128 @@
+---
+title: <picture>:picture 元素
+slug: Web/HTML/Element/picture
+tags:
+ - HTML
+ - Web
+ - picture
+ - 元素
+ - 图片
+ - 引用
+translation_of: Web/HTML/Element/picture
+---
+<div>{{HTMLRef}}</div>
+
+<p><span class="seoSummary"><strong>HTML <code>&lt;picture&gt;</code> 元素</strong>通过包含零或多个 {{HTMLElement("source")}} 元素和一个 {{HTMLElement("img")}} 元素来为不同的显示/设备场景提供图像版本。浏览器会选择最匹配的子 <code>&lt;source&gt;</code> 元素,如果没有匹配的,就选择 <code>&lt;img&gt;</code> 元素的 {{htmlattrxref("src", "img")}} 属性中的URL。然后,所选图像呈现在&lt;img&gt;元素占据的空间中。</span></p>
+
+<div>{{EmbedInteractiveExample("pages/tabbed/picture.html", "tabbed-standard")}}</div>
+
+<p class="hidden">The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples </a> and send us a pull request.</p>
+
+<p><span class="tlid-translation translation" lang="zh-CN"><span title="">要决定加载哪个URL</span></span>,{{Glossary("user agent")}} 检查每个 <code>&lt;source&gt;</code> 的 {{htmlattrxref("srcset", "source")}}、{{htmlattrxref("media", "source")}} 和 {{htmlattrxref("type", "source")}} 属性<span class="tlid-translation translation" lang="zh-CN"><span title="">,来选择最匹配页面当前布局、显示设备特征等的兼容图像。</span></span></p>
+
+<p><code>&lt;picture&gt;</code> 的常见使用场景:</p>
+
+<ul>
+ <li><span class="tlid-translation translation" lang="zh-CN"><span title="">艺术指导(</span></span>Art direction<span class="tlid-translation translation" lang="zh-CN"><span title="">) —— 针对不同 <code>media</code> 条件裁剪或修改图像</span></span></li>
+ <li>遇到所有浏览器都不支持的特定格式时,提供不同的图像格式</li>
+</ul>
+
+<p>If providing higher-density versions of an image for high-DPI (Retina) display, use {{htmlattrxref("srcset", "img")}} on the <code>&lt;img&gt;</code> element instead. This lets browsers opt for lower-density versions in data-saving modes, and you don't have to write explicit <code>media</code> conditions.</p>
+
+<table class="properties">
+ <tbody>
+ <tr>
+ <th scope="row"><a href="/en-US/docs/Web/HTML/Content_categories">内容分类</a></th>
+ <td><a href="/en-US/docs/Web/HTML/Content_categories#Flow_content">流内容</a>,表述内容,嵌入内容。</td>
+ </tr>
+ <tr>
+ <th scope="row">允许的内容</th>
+ <td>零或多个 {{HTMLElement("source")}} 元素,以及紧随其后的一个 {{HTMLElement("img")}} 元素,可以混合一些脚本支持的元素。</td>
+ </tr>
+ <tr>
+ <th scope="row">标签省略</th>
+ <td>{{no_tag_omission}}</td>
+ </tr>
+ <tr>
+ <th scope="row">允许的父元素</th>
+ <td>任何可以包含嵌入内容的元素。</td>
+ </tr>
+ <tr>
+ <th scope="row">允许的 ARIA roles</th>
+ <td>无</td>
+ </tr>
+ <tr>
+ <th scope="row">DOM 接口</th>
+ <td>{{domxref("HTMLPictureElement")}}</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="属性">属性</h2>
+
+<p>这个元素只包含<a href="/en-US/docs/Web/HTML/Global_attributes">全局属性</a>。</p>
+
+<h2 id="用法提示">用法提示</h2>
+
+<p>你可以使用 {{cssxref("object-position")}} 属性<span class="tlid-translation translation" lang="zh-CN"><span title="">调整元素框架内图像的位置</span></span>,用 {{cssxref("object-fit")}} 属性控制图片如何调整大小来适应框架。</p>
+
+<div class="note">
+<p><strong>提示:</strong>在子 <code>&lt;img&gt;</code> 元素上使用这些属性,不是 <code>&lt;picture&gt;</code> 元素。</p>
+</div>
+
+<h2 id="示例">示例</h2>
+
+<p><span class="tlid-translation translation" lang="zh-CN"><span title="">这些示例演示了 </span></span>{{HTMLElement("source")}} 元素<span class="tlid-translation translation" lang="zh-CN"><span title="">的不同属性如何更改<code>&lt;picture&gt;</code>中图像的选择。</span></span></p>
+
+<h3 id="media_属性"><code>media</code> 属性</h3>
+
+<p><code>media</code> 属性允许你提供一个用于给用户代理作为选择 {{HTMLElement("source")}} 元素的依据的媒体条件(media condition)(类似于媒体查询)。如果这个媒体条件匹配结果为 <code>false</code>,那么这个 {{HTMLElement("source")}} 元素会被跳过。</p>
+
+<pre class="brush: html">&lt;picture&gt;
+ &lt;source srcset="mdn-logo-wide.png" media="(min-width: 600px)"&gt;
+ &lt;img src="mdn-logo-narrow.png" alt="MDN"&gt;
+&lt;/picture&gt;
+</pre>
+
+<h3 id="type_属性"><code>type</code> 属性</h3>
+
+<p><code>type</code> 属性允许你为 {{HTMLElement("source")}} 元素的 <code>srcset</code> 属性指向的资源指定一个 <a href="/zh-CN/docs/Web/HTTP/Basics_of_HTTP/MIME_types">MIME 类型</a>。如果用户代理不支持指定的类型,那么这个 {{HTMLElement("source")}} 元素会被跳过。</p>
+
+<pre class="brush: html">​&lt;picture&gt;
+ &lt;source srcset="mdn-logo.svg" type="image/svg+xml"&gt;
+ &lt;img src="mdn-logo.png" alt="MDN"&gt;
+&lt;/picture&gt;
+</pre>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">规范</th>
+ <th scope="col">状态</th>
+ <th scope="col">备注</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName('HTML WHATWG', 'embedded-content.html#the-picture-element', '&lt;picture&gt;')}}</td>
+ <td>{{Spec2('HTML WHATWG')}}</td>
+ <td>初始定义</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+
+
+<p>{{Compat("html.elements.picture")}}</p>
+
+<h2 id="参考链接">参考链接</h2>
+
+<ul>
+ <li>{{HTMLElement("img")}} 元素</li>
+ <li>{{HTMLElement("source")}} 元素</li>
+ <li>在其框架内定位和缩放图片:{{cssxref("object-position")}} 和 {{cssxref("object-fit")}}</li>
+</ul>