diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/css/@viewport/index.html | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/css/@viewport/index.html')
-rw-r--r-- | files/zh-cn/web/css/@viewport/index.html | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/files/zh-cn/web/css/@viewport/index.html b/files/zh-cn/web/css/@viewport/index.html new file mode 100644 index 0000000000..b1b7b23175 --- /dev/null +++ b/files/zh-cn/web/css/@viewport/index.html @@ -0,0 +1,120 @@ +--- +title: '@viewport' +slug: Web/CSS/@viewport +tags: + - Adaptation + - At-rule + - CSS + - Device + - NeedsContent + - NeedsTranslation + - Reference + - TopicStub +translation_of: Web/CSS/@viewport +--- +<div>{{CSSRef}}{{deprecated_header}}</div> + +<p><strong> <code>@viewport</code></strong> 规则让我们可以对文档的大小进行设置 {{glossary("viewport")}} 。这个特性主要被用于移动设备,但是也可以用在支持类似“固定到边缘”等特性的桌面浏览器,如微软的Edge。</p> + +<p>按百分比计算尺寸的时候,就是参照的<strong>初始视口(viewport)</strong>。初始视口指的是任何用户代理和样式对它进行修改之前的视口。桌面浏览器如果不是全屏模式的话,一般是基于窗口大小。</p> + +<p>在移动设备上(或者桌面浏览器的全屏模式),初始视口通常就是应用程序可以使用的屏幕部分。它可能是全屏或者减去由操作系统或者其它应用程序所占用的部分(例如状态栏)。</p> + +<pre class="brush: css no-line-numbers notranslate">@viewport { + width: 100vw; /*将视口宽度设为与设备宽度相同*/ +}</pre> + +<h2 id="语法">语法</h2> + +<p>@规则包含一组包含在CSS代码块中的嵌套的 {{glossary("descriptor (CSS)", "descriptor")}}。</p> + +<p>缩放因子<code>1.0</code> 或者 <code>100%</code> 表示不缩放,大于1表示放大,小于1表示缩小。</p> + +<h3 id="描述符">描述符</h3> + +<p>目前,大多数浏览器对 <code>@viewport</code> 的支持很差,Internet Explorer和Edge对其支持较好。但即使在这些浏览器中,也只有少量的描述符可用。如果浏览器不支持 <code>@viewport</code>,浏览器会忽略 <code>@viewport</code> 以及任何和其相关的描述符。</p> + +<dl> + <dt><a href="/en-US/docs/Web/CSS/@viewport/min-width"><code>min-width</code></a></dt> + <dd>设置viewport的最小宽度</dd> + <dt><a href="/en-US/docs/Web/CSS/@viewport/max-width"><code>max-width</code></a></dt> + <dd>设置viewport的最大宽度</dd> + <dt><a href="/en-US/docs/Web/CSS/@viewport/width"><code>width</code></a></dt> + <dd>同时设置 <code>min-width</code> 和 <code>max-width</code></dd> + <dt><a href="/en-US/docs/Web/CSS/@viewport/min-height"><code>min-height</code></a></dt> + <dd>设置viewport的最小高度</dd> + <dt><a href="/en-US/docs/Web/CSS/@viewport/max-height"><code>max-height</code></a></dt> + <dd>设置viewport的最大高度</dd> + <dt><a href="/en-US/docs/Web/CSS/@viewport/height"><code>height</code></a></dt> + <dd>同时设置 <code>min-height</code> 和 <code>max-height</code></dd> + <dt><a href="/en-US/docs/Web/CSS/@viewport/zoom"><code>zoom</code></a></dt> + <dd>设置初始缩放系数</dd> + <dt><a href="/en-US/docs/Web/CSS/@viewport/min-zoom"><code>min-zoom</code></a></dt> + <dd>设置最小缩放系数</dd> + <dt><a href="/en-US/docs/Web/CSS/@viewport/max-zoom"><code>max-zoom</code></a></dt> + <dd>设置最大缩放系数</dd> + <dt><a href="/en-US/docs/Web/CSS/@viewport/user-zoom"><code>user-zoom</code></a></dt> + <dd>设置用户是能更改缩放系数</dd> + <dt><a href="/en-US/docs/Web/CSS/@viewport/orientation"><code>orientation</code></a></dt> + <dd>设置文档的方向</dd> + <dt>{{cssxref("@viewport/viewport-fit", "viewport-fit")}}</dt> + <dd>Controls the display of the document on non-rectangular displays.</dd> +</dl> + +<h3 id="Formal_syntax">Formal syntax</h3> + +<pre class="syntaxbox notranslate">{{csssyntax}}</pre> + +<h2 id="Examples">Examples</h2> + +<pre class="brush: css notranslate">@viewport { + min-width: 640px; + max-width: 800px; +} + +@viewport { + zoom: 0.75; + min-zoom: 0.5; + max-zoom: 0.9; +} + +@viewport { + orientation: landscape; +}</pre> + +<h2 id="Specifications" name="Specifications">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("CSS Round Display", "#extending-viewport-rule", "@viewport")}}</td> + <td>{{Spec2("CSS Round Display")}}</td> + <td>Defined the {{cssxref("@viewport/viewport-fit", "viewport-fit")}} descriptor.</td> + </tr> + <tr> + <td>{{SpecName('CSS3 Device', '#the-atviewport-rule', '@viewport')}}</td> + <td>{{Spec2('CSS3 Device')}}</td> + <td>Initial definition</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + + + +<p>{{Compat("css.at-rules.viewport")}}</p> + +<h2 id="See_also">See also</h2> + +<ul> + <li>{{HTMLElement("meta")}}, specifically <code><meta name="viewport"></code></li> + <li><a href="/en-US/docs/Mobile/Viewport_meta_tag">Using the viewport meta tag to control layout on mobile browsers</a></li> +</ul> |