aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/css/@media/aspect-ratio
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/@media/aspect-ratio
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/@media/aspect-ratio')
-rw-r--r--files/zh-cn/web/css/@media/aspect-ratio/index.html120
1 files changed, 120 insertions, 0 deletions
diff --git a/files/zh-cn/web/css/@media/aspect-ratio/index.html b/files/zh-cn/web/css/@media/aspect-ratio/index.html
new file mode 100644
index 0000000000..d18fb02b2b
--- /dev/null
+++ b/files/zh-cn/web/css/@media/aspect-ratio/index.html
@@ -0,0 +1,120 @@
+---
+title: aspect-ratio
+slug: Web/CSS/@media/aspect-ratio
+translation_of: Web/CSS/@media/aspect-ratio
+---
+<div>{{cssref}}</div>
+
+<p><strong><code>aspect-ratio</code></strong> <a href="/zh-CN/docs/CSS">CSS</a> <a href="/zh-CN/docs/Web/CSS/Media_Queries/Using_media_queries#Media_features">媒体属性</a> 可以用来测试 {{glossary("viewport")}} 的宽高比。</p>
+
+<h2 id="语法">语法</h2>
+
+<p>宽高比属性被指定为{{cssxref("&lt;ratio&gt;")}}值来代表viewport的宽高比。其为一个范围,这意味着你可以使用<strong><code>min-aspect-ratio</code></strong>和<code><strong>max-aspect-ratio</strong></code>分别查询最小和最大的值。</p>
+
+<h2 id="例子">例子</h2>
+
+<p>下面的例子包含一个 {{htmlElement("iframe")}} ,拥有它自身的viewport。调整的<code>&lt;iframe&gt;</code>宽高来观察<code>aspect-ratio</code>的变化。</p>
+
+<h3 id="HTML">HTML</h3>
+
+<pre class="brush: html notranslate">&lt;div id='inner'&gt;
+  Watch this element as you resize your viewport's width and height.
+&lt;/div&gt;
+</pre>
+
+<h3 id="CSS">CSS</h3>
+
+<pre class="brush: css notranslate">/* 最小宽高比 */
+@media (min-aspect-ratio: 8/5) {
+  div {
+    background: #9af; /* blue */
+  }
+}
+
+/* 最大宽高比 */
+@media (max-aspect-ratio: 3/2) {
+  div {
+    background: #9ff;  /* cyan */
+  }
+}
+
+/* 明确的宽高比, 放在最下部防止同时满足条件时的覆盖*/
+@media (aspect-ratio: 1/1) {
+  div {
+    background: #f9a; /* red */
+  }
+}
+</pre>
+
+<div class="hidden">
+<h2 id="_Example">_Example</h2>
+
+<p>used iframe and DataURL to enable this iframe could resize</p>
+
+<h3 id="HTML_2">HTML</h3>
+
+<pre class="brush: html notranslate">&lt;label id="wf" for="w"&gt;width:165&lt;/label&gt;
+&lt;input id="w" name="w" type="range" min="100" max="250" step="5" value="165"&gt;
+&lt;label id="hf" for="w"&gt;height:165&lt;/label&gt;
+&lt;input id="h" name="h" type="range" min="100" max="250" step="5" value="165"&gt;
+
+&lt;iframe id="outer" src="data:text/html,&lt;style&gt; @media (min-aspect-ratio: 8/5) { div { background: %239af; } } @media (max-aspect-ratio: 3/2) { div { background: %239ff; } } @media (aspect-ratio: 1/1) { div { background: %23f9a; } }&lt;/style&gt;&lt;div id='inner'&gt; Watch this element as you resize your viewport's width and height.&lt;/div&gt;"&gt;
+
+&lt;/iframe&gt;
+</pre>
+
+<h3 id="CSS_2">CSS</h3>
+
+<pre class="brush: css notranslate">iframe{
+  display:block;
+}</pre>
+
+<h3 id="JavaScript">JavaScript</h3>
+
+<pre class="brush: js notranslate">outer.style.width=outer.style.height="165px"
+
+w.onchange=w.oninput=function(){
+ outer.style.width=w.value+"px"
+ wf.textContent="width:"+w.value
+}
+h.onchange=h.oninput=function(){
+ outer.style.height=h.value+"px"
+ hf.textContent="height:"+h.value
+}</pre>
+</div>
+
+<h3 id="结果">结果</h3>
+
+<div style="overflow: auto;">
+<p>{{ EmbedLiveSample('_Example', '300px', '400px') }}</p>
+</div>
+
+<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('CSS4 Media Queries', '#aspect-ratio', 'aspect-ratio')}}</td>
+ <td>{{Spec2('CSS4 Media Queries')}}</td>
+ <td>No change.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('CSS3 Media Queries', '#aspect-ratio', 'aspect-ratio')}}</td>
+ <td>{{Spec2('CSS3 Media Queries')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+
+
+<p>{{Compat("css.at-rules.media.aspect-ratio")}}</p>