Lzh on GitHub

max-height

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

快速参考

类名样式
max-h-<number>max-height: calc(var(--spacing) * <number>);
max-h-<fraction>max-height: calc(<fraction> * 100%);
max-h-nonemax-height: none;
max-h-pxmax-height: 1px;
max-h-fullmax-height: 100%;
max-h-screenmax-height: 100vh;
max-h-dvhmax-height: 100dvh;
max-h-dvwmax-height: 100dvw;
max-h-lvhmax-height: 100lvh;
max-h-lvwmax-height: 100lvw;
max-h-svhmax-height: 100svh;
max-h-svwmax-height: 100svw;
max-h-minmax-height: min-content;
max-h-maxmax-height: max-content;
max-h-fitmax-height: fit-content;
max-h-lhmax-height: 1lh;
max-h-(<custom-property>)max-height: var(<custom-property>);
max-h-[<value>]max-height: <value>;

示例

基本示例

使用 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>] 语法根据完全自定义的值设置 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;
}

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