max-height
设置元素最大高度的实用工具。
快速参考
| 类名 | 样式 |
|---|---|
max-h-<number> | max-height: calc(var(--spacing) * <number>); |
max-h-<fraction> | max-height: calc(<fraction> * 100%); |
max-h-none | max-height: none; |
max-h-px | max-height: 1px; |
max-h-full | max-height: 100%; |
max-h-screen | max-height: 100vh; |
max-h-dvh | max-height: 100dvh; |
max-h-dvw | max-height: 100dvw; |
max-h-lvh | max-height: 100lvh; |
max-h-lvw | max-height: 100lvw; |
max-h-svh | max-height: 100svh; |
max-h-svw | max-height: 100svw; |
max-h-min | max-height: min-content; |
max-h-max | max-height: max-content; |
max-h-fit | max-height: fit-content; |
max-h-lh | max-height: 1lh; |
max-h-(<custom-property>) | max-height: var(<custom-property>); |
max-h-[<value>] | max-height: <value>; |
示例
基本示例
使用 max-h-<number> 实用工具(如 max-h-24 和 max-h-64)根据间距比例将元素的最大高度设置为固定值:
max-h-80
max-h-64
max-h-48
max-h-40
max-h-32
max-h-24
<div class="h-96 ...">
<div class="h-full max-h-80 ...">max-h-80</div>
<div class="h-full max-h-64 ...">max-h-64</div>
<div class="h-full max-h-48 ...">max-h-48</div>
<div class="h-full max-h-40 ...">max-h-40</div>
<div class="h-full max-h-32 ...">max-h-32</div>
<div class="h-full max-h-24 ...">max-h-24</div>
</div>
使用百分比
使用 max-h-full 或 max-h-<fraction> 实用工具(如 max-h-1/2 和 max-h-2/5)为元素设置基于百分比的最大高度:
max-h-9/10
max-h-3/4
max-h-1/2
max-h-1/4
max-h-full
<div class="h-96 ...">
<div class="h-full max-h-9/10 ...">max-h-9/10</div>
<div class="h-full max-h-3/4 ...">max-h-3/4</div>
<div class="h-full max-h-1/2 ...">max-h-1/2</div>
<div class="h-full max-h-1/4 ...">max-h-1/4</div>
<div class="h-full max-h-full ...">max-h-full</div>
</div>
使用自定义值
使用 max-h-[<value>] 语法根据完全自定义的值设置 maximum height:
<div class="max-h-[220px] ...">
<!-- ... -->
</div>
对于 CSS 变量,您还可以使用 max-h-(<custom-property>) 语法:
<div class="max-h-(--my-max-height) ...">
<!-- ... -->
</div>
这只是 max-h-[var(<custom-property>)] 的简写形式,它会自动为您添加 var() 函数。
响应式设计
使用断点变体(例如 md:)作为 max-height 实用工具的前缀,以便仅在中等尺寸及以上的屏幕上应用该实用工具:
<div class="h-48 max-h-full md:max-h-screen ...">
<!-- ... -->
</div>
在 变体文档 中了解更多关于使用变体的信息。
自定义您的主题
max-h-<number> 实用工具由 --spacing 主题变量驱动,该变量可以在您自己的主题中进行自定义:
@theme {
--spacing: 1px;
}
在 主题变量文档 中了解更多关于自定义间距比例的信息。