aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/css/max-height/index.html
blob: da35b710d399b54eb6dc2b56a97aebd104a09f12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
---
title: max-height
slug: Web/CSS/max-height
translation_of: Web/CSS/max-height
---
<div>{{CSSRef}}</div>

<p><a href="/en-US/docs/Web/CSS">CSS</a>属性 <strong><code>max-height</code></strong> 设置元素的最大高度。它防止{{cssxref("height")}}属性的使用值(<a href="/en-US/docs/Web/CSS/used_value">used value</a>) 大于 <code>max-height</code> 的指定值。</p>

<div>{{EmbedInteractiveExample("pages/css/max-height.html")}}</div>

<div 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.</div>

<p><code>max-height</code> 会覆盖{{cssxref("height")}}, 而{{cssxref("min-height")}} 会覆盖 <code>max-height</code>.</p>

<h2 id="Syntax" name="Syntax">Syntax</h2>

<pre class="brush:css no-line-numbers notranslate">/* &lt;length&gt; value */
max-height: 3.5em;

/* &lt;percentage&gt; value */
max-height: 75%;

/* Keyword values */
max-height: none;
max-height: max-content;
max-height: min-content;
max-height: fit-content(20em);

/* Global values */
max-height: inherit;
max-height: initial;
max-height: unset;
</pre>

<h3 id="Values" name="Values">Values</h3>

<dl>
 <dt>{{cssxref("&lt;length&gt;")}}</dt>
 <dd>Defines the <code>max-height</code> as an absolute value.</dd>
 <dt>{{cssxref("&lt;percentage&gt;")}}</dt>
 <dd>Defines the <code>max-height</code> as a percentage of the containing block's height.</dd>
 <dt><code>auto</code></dt>
 <dd>The browser will calculate and select a <code>max-height</code> for the specified element.</dd>
 <dt><code>none</code></dt>
 <dd>No limit on the size of the box.</dd>
 <dt><code>max-content</code></dt>
 <dd>The intrinsic preferred <code>max-height</code>.</dd>
 <dt><code>min-content</code></dt>
 <dd>The intrinsic minimum <code>max-height</code>.</dd>
 <dt><code>fit-content({{cssxref("&lt;length-percentage&gt;")}})</code></dt>
 <dd>Uses the <code>fit-content</code> formula with the available space replaced by the specified argument, i.e. <code>min(max-content, max(min-content, <var>argument</var>))</code>.</dd>
</dl>

<h3 id="Formal_syntax">Formal syntax</h3>

{{csssyntax}}

<h2 id="Examples">Examples</h2>

<pre class="brush: css notranslate">table { max-height: 75%; }

form { max-height: none; }
</pre>

<h2 id="Accessibility_concerns">Accessibility concerns</h2>

<p>Ensure that elements set with a <code>max-height</code> are not truncated and/or do not obscure other content when the page is zoomed to increase text size.</p>

<ul>
 <li><a href="/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" rel="noopener">Understanding Success Criterion 1.4.4 | W3C Understanding WCAG 2.0</a></li>
</ul>

<h2 id="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('CSS4 Sizing', '#width-height-keywords', 'max-height')}}</td>
   <td>{{Spec2('CSS4 Sizing')}}</td>
   <td></td>
  </tr>
  <tr>
   <td>{{SpecName('CSS3 Sizing', '#width-height-keywords', 'max-height')}}</td>
   <td>{{Spec2('CSS3 Sizing')}}</td>
   <td>Adds the <code>max-content</code>, <code>min-content</code>, <code>fit-content</code> keywords.</td>
  </tr>
  <tr>
   <td>{{SpecName('CSS2.1', 'visudet.html#min-max-heights', 'max-height')}}</td>
   <td>{{ Spec2('CSS2.1') }}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<p>{{cssinfo}}</p>

<h2 id="Browser_compatibility" name="Browser_compatibility">Browser compatibility</h2>

<div class="hidden">The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</div>

<p>{{Compat("css.properties.max-height")}}</p>

<h2 id="See_also" name="See_also">See also</h2>

<ul>
 <li><a href="/en-US/docs/Web/CSS/CSS_Box_Model/Introduction_to_the_CSS_box_model" title="en/CSS/box_model">The box model</a>, {{cssxref("box-sizing")}}</li>
 <li>{{Cssxref("height")}}, {{Cssxref("min-height")}}</li>
</ul>