1. 大小
  2. height

大小

高度

用于设置元素高度的工具类。

ClassStyles
h-<number>
height: calc(var(--spacing) * <number>);
h-<fraction>
height: calc(<fraction> * 100%);
h-auto
height: auto;
h-px
height: 1px;
h-full
height: 100%;
h-screen
height: 100vh;
h-dvh
height: 100dvh;
h-dvw
height: 100dvw;
h-lvh
height: 100lvh;
h-lvw
height: 100lvw;

示例

基础示例

使用像 h-24h-64 这样的 h-<number> 工具类来基于间距比例将元素设置为固定高度:

h-96
h-80
h-64
h-48
h-40
h-32
h-24
<div class="h-96 ...">h-96</div><div class="h-80 ...">h-80</div><div class="h-64 ...">h-64</div><div class="h-48 ...">h-48</div><div class="h-40 ...">h-40</div><div class="h-32 ...">h-32</div><div class="h-24 ...">h-24</div>

使用百分比

使用 h-full 或像 h-1/2h-2/5 这样的 h-<fraction> 工具类来给元素设置基于百分比的高度:

h-full
h-9/10
h-3/4
h-1/2
h-1/3
<div class="h-full ...">h-full</div><div class="h-9/10 ...">h-9/10</div><div class="h-3/4 ...">h-3/4</div><div class="h-1/2 ...">h-1/2</div><div class="h-1/3 ...">h-1/3</div>

匹配视口

使用 h-screen 工具类来使元素跨越整个视口高度:

<div class="h-screen">  <!-- ... --></div>

匹配动态视口

使用 h-dvh 工具类来使元素跨越整个视口高度,该高度会随着浏览器UI的展开或收缩而变化:

Scroll the viewport to see the viewport height change

tailwindcss.com

h-dvh

<div class="h-dvh">  <!-- ... --></div>

匹配大视口

使用 h-lvh 工具类来将元素的高度设置为视口的最大可能高度:

Scroll the viewport to see the viewport height change

tailwindcss.com

h-lvh

<div class="h-lvh">  <!-- ... --></div>

匹配小视口

使用 h-svh 工具类来将元素的高度设置为视口的最小可能高度:

Scroll the viewport to see the viewport height change

tailwindcss.com

h-svh

<div class="h-svh">  <!-- ... --></div>

同时设置宽度和高度

使用像 size-pxsize-4size-full 这样的工具类来同时设置元素的宽度和高度:

size-16
size-20
size-24
<div class="size-16 ...">size-16</div><div class="size-20 ...">size-20</div><div class="size-24 ...">size-24</div><div class="size-32 ...">size-32</div><div class="size-40 ...">size-40</div>

使用自定义值

Use the h-[<value>] syntax to set the 高度 based on a completely custom value:

<div class="h-[32rem] ...">  <!-- ... --></div>

For CSS variables, you can also use the h-(<custom-property>) syntax:

<div class="h-(--my-height) ...">  <!-- ... --></div>

This is just a shorthand for h-[var(<custom-property>)] that adds the var() function for you automatically.

响应式设计

Prefix a height utility with a breakpoint variant like md: to only apply the utility at medium screen sizes and above:

<div class="h-1/2 md:h-full ...">  <!-- ... --></div>

Learn more about using variants in the variants documentation.

定制您的主题

The h-<number> and size-<number> utilities are driven by the --spacing theme variable, which can be customized in your own theme:

@theme {  --spacing: 1px; }

Learn more about customizing the spacing scale in the theme variable documentation.

Copyright © 2025 Tailwind Labs Inc.·Trademark Policy