aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/css/height/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/height/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/height/index.html')
-rw-r--r--files/zh-cn/web/css/height/index.html167
1 files changed, 167 insertions, 0 deletions
diff --git a/files/zh-cn/web/css/height/index.html b/files/zh-cn/web/css/height/index.html
new file mode 100644
index 0000000000..1666465e3f
--- /dev/null
+++ b/files/zh-cn/web/css/height/index.html
@@ -0,0 +1,167 @@
+---
+title: height
+slug: Web/CSS/height
+tags:
+ - CSS
+ - CSS Property
+ - Reference
+translation_of: Web/CSS/height
+---
+<div>{{CSSRef()}}</div>
+
+<div><code>height</code> CSS 属性指定了一个元素的高度。默认情况下,这个属性决定的是内容区( <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Introduction_to_the_CSS_box_model#content-area">content area</a>)的高度,但是,如果将 {{cssxref("box-sizing")}} 设置为  <code>border-box</code> , 这个属性决定的将是边框区域(<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Introduction_to_the_CSS_box_model#border-area">border area</a>)的高度。</div>
+
+<div>{{EmbedInteractiveExample("pages/css/height.html")}}</div>
+
+<div>{{cssxref("min-height")}} 和 {{cssxref("max-height")}} 属性会覆盖  {{Cssxref("height")}}。</div>
+
+<h2 id="Syntax" name="Syntax">语法</h2>
+
+<pre class="brush:css no-line-numbers">/* Keyword value */
+height: auto;
+
+/* &lt;length&gt; values */
+height: 120px;
+height: 10em;
+
+/* &lt;percentage&gt; value */
+height: 75%;
+
+/* Global values */
+height: inherit;
+height: initial;
+height: unset;</pre>
+
+<h3 id="值">值</h3>
+
+<dl>
+ <dt>{{cssxref("&lt;length&gt;")}}</dt>
+ <dd>将高度定义为一个绝对值。</dd>
+ <dt>{{cssxref("&lt;percentage&gt;")}}</dt>
+ <dd>将高度定义为相对包含块高度的百分比。</dd>
+ <dt><code>border-box</code> {{experimental_inline}}</dt>
+ <dd>如果设置该值,则 {{cssxref("&lt;length&gt;")}} 或者 {{cssxref("&lt;percentage&gt;")}} 会设置为该元素的 border box。</dd>
+ <dt><code>content-box</code> {{experimental_inline}}</dt>
+ <dd>如果设置该值,则 {{cssxref("&lt;length&gt;")}} 或者 {{cssxref("&lt;percentage&gt;")}} 会设置为该元素的 content box。</dd>
+</dl>
+
+<dl>
+ <dt><code>auto</code></dt>
+ <dd>由浏览器为元素计算并选择一个高度。</dd>
+ <dt><code>fill</code> {{experimental_inline}}</dt>
+ <dd>根据文字方向,使用 <code>fill-available</code> 作为行大小或者块大小。</dd>
+ <dt><code>max-content</code> {{experimental_inline}}</dt>
+ <dd>设置为允许的最大高度。</dd>
+ <dt><code>min-content</code> {{experimental_inline}}</dt>
+ <dd>设置为允许的最小高度.</dd>
+ <dt><code>available</code> {{experimental_inline}}</dt>
+ <dd>包含块高度减去当前元素的边距,边框和填充。</dd>
+ <dt><code>fit-content</code> {{experimental_inline}}</dt>
+ <dd>将 fill-content 公式中的可用位置替换为特定的参数以进行使用,如:min(max-content, max(min-content, ))</dd>
+</dl>
+
+<h3 id="Formal_syntax">Formal syntax</h3>
+
+<pre class="syntaxbox">{{csssyntax}}</pre>
+
+<h2 id="示例">示例</h2>
+
+<h3 id="HTML">HTML</h3>
+
+<pre class="brush: html">&lt;div id="taller"&gt;I'm 50 pixels tall.&lt;/div&gt;
+&lt;div id="shorter"&gt;I'm 25 pixels tall.&lt;/div&gt;
+&lt;div id="parent"&gt;
+ &lt;div id="child"&gt;
+ I'm half the height of my parent.
+ &lt;/div&gt;
+&lt;/div&gt;</pre>
+
+<h3 id="CSS">CSS</h3>
+
+<pre class="brush: css">div {
+ width: 250px;
+ margin-bottom: 5px;
+ border: 2px solid blue;
+}
+
+#taller {
+ height: 50px;
+}
+
+#shorter {
+ height: 25px;
+}
+
+#parent {
+ height: 100px;
+}
+
+#child {
+ height: 50%;
+ width: 75%;
+}
+</pre>
+
+<h3 id="结果">结果</h3>
+
+<p>{{EmbedLiveSample('示例', 'auto', 240)}}</p>
+
+<h2 id="无障碍问题">无障碍问题</h2>
+
+<p>确保设定了 <code>height</code> 的元素在显示上不会被截断,或者当页面放大时增大的字体大小不会遮挡其他内容。 </p>
+
+<ul>
+ <li><a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#Guideline_1.4_Make_it_easier_for_users_to_see_and_hear_content_including_separating_foreground_from_background">MDN Understanding WCAG, Guideline 1.4 explanations</a></li>
+ <li><a href="https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-scale.html">Understanding Success Criterion 1.4.4  | W3C Understanding WCAG 2.0</a></li>
+</ul>
+
+<h2 id="规范">规范</h2>
+
+<table>
+ <thead>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName('CSS3 Box', '#the-width-and-height-properties', 'height')}}</td>
+ <td>{{Spec2('CSS3 Box')}}</td>
+ <td>Added the <code>max-content</code>, <code>min-content</code>, <code>available</code>, <code>fit-content</code>, <code>border-box</code>, <code>content-box</code>keywords.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('CSS3 Transitions', '#animatable-css', 'height')}}</td>
+ <td>{{Spec2('CSS3 Transitions')}}</td>
+ <td>Lists <code>height</code> as animatable.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('CSS2.1', 'visudet.html#the-height-property', 'height')}}</td>
+ <td>{{Spec2('CSS2.1')}}</td>
+ <td>Adds support for the {{cssxref("&lt;length&gt;")}} values and precises on which element it applies to.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('CSS1', '#height', 'height')}}</td>
+ <td>{{Spec2('CSS1')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('CSS3 Sizing', '#width-height-keywords', 'width')}}</td>
+ <td>{{Spec2('CSS3 Sizing')}}</td>
+ <td>Adds new sizing keywords for width and height.</td>
+ </tr>
+ </tbody>
+</table>
+
+<p>{{cssinfo}}</p>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<p>{{Compat("css.properties.height")}}</p>
+
+<h2 id="See_also" name="See_also">参见</h2>
+
+<ul>
+ <li><a href="https://developer.mozilla.org/en-US/docs/CSS/box_model">box model</a>, {{cssxref("width")}}, {{cssxref("box-sizing")}}, {{cssxref("min-height")}}, {{cssxref("max-height")}}</li>
+</ul>