1. 尺寸
  2. 最大高度

尺寸

最大高度

用于设置元素最大高度的实用工具。

类名样式
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-<number> 实用工具,例如 max-h-24max-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-fullmax-h-<fraction> 实用工具,例如 max-h-1/2max-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>] 语法 来设置最大高度基于完全自定义的值

<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() 函数。

响应式设计

前缀a max-height 实用工具 与断点变体(如 md:)一起使用,以仅在中等 屏幕尺寸及以上尺寸应用该实用工具

<div class="h-48 max-h-full md:max-h-screen ...">
<!-- ... -->
</div>

了解有关在变体文档中使用变体的更多信息。

自定义您的主题

max-h-<number> 实用工具由 --spacing 主题变量驱动,该变量可以在您自己的主题中自定义

@theme {
--spacing: 1px;
}

了解有关在主题变量文档中自定义间距比例的更多信息。

版权所有 © 2025 Tailwind Labs Inc.·商标政策