Sizing

max-height

用於設定元素最大高度的通用類別。

ClassStyles
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;

範例(Examples)

基本範例(Basic example)

使用 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>

使用百分比(Using a percentage)

使用 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>

使用自訂值(Using a custom value)

使用 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() 函式。

響應式設計(Responsive design)

max-height 通用類別前面加上像 md: 這樣的中斷點變體,讓該通用類別只在中型螢幕尺寸及以上時套用:

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

變體文件中了解更多關於使用變體的資訊。

自訂主題(Customizing your theme)

max-h-<number> 通用類別由 --spacing 主題變數驅動,可以在你自己的主題中自訂:

@theme {  --spacing: 1px; }

主題變數文件中了解更多關於自訂間距比例的資訊。

Copyright © 2026 Tailwind Labs Inc.·商標政策(Brand)