1. 尺寸
  2. 高度

Quick reference

Class
Properties
h-0height: 0px;
h-pxheight: 1px;
h-0.5height: 0.125rem; /* 2px */
h-1height: 0.25rem; /* 4px */
h-1.5height: 0.375rem; /* 6px */
h-2height: 0.5rem; /* 8px */
h-2.5height: 0.625rem; /* 10px */
h-3height: 0.75rem; /* 12px */
h-3.5height: 0.875rem; /* 14px */
h-4height: 1rem; /* 16px */
h-5height: 1.25rem; /* 20px */
h-6height: 1.5rem; /* 24px */
h-7height: 1.75rem; /* 28px */
h-8height: 2rem; /* 32px */
h-9height: 2.25rem; /* 36px */
h-10height: 2.5rem; /* 40px */
h-11height: 2.75rem; /* 44px */
h-12height: 3rem; /* 48px */
h-14height: 3.5rem; /* 56px */
h-16height: 4rem; /* 64px */
h-20height: 5rem; /* 80px */
h-24height: 6rem; /* 96px */
h-28height: 7rem; /* 112px */
h-32height: 8rem; /* 128px */
h-36height: 9rem; /* 144px */
h-40height: 10rem; /* 160px */
h-44height: 11rem; /* 176px */
h-48height: 12rem; /* 192px */
h-52height: 13rem; /* 208px */
h-56height: 14rem; /* 224px */
h-60height: 15rem; /* 240px */
h-64height: 16rem; /* 256px */
h-72height: 18rem; /* 288px */
h-80height: 20rem; /* 320px */
h-96height: 24rem; /* 384px */
h-autoheight: auto;
h-1/2height: 50%;
h-1/3height: 33.333333%;
h-2/3height: 66.666667%;
h-1/4height: 25%;
h-2/4height: 50%;
h-3/4height: 75%;
h-1/5height: 20%;
h-2/5height: 40%;
h-3/5height: 60%;
h-4/5height: 80%;
h-1/6height: 16.666667%;
h-2/6height: 33.333333%;
h-3/6height: 50%;
h-4/6height: 66.666667%;
h-5/6height: 83.333333%;
h-fullheight: 100%;
h-screenheight: 100vh;
h-svhheight: 100svh;
h-lvhheight: 100lvh;
h-dvhheight: 100dvh;
h-minheight: min-content;
h-maxheight: max-content;
h-fitheight: fit-content;

基本用法

¥Basic usage

固定高度

¥Fixed heights

使用 h-pxh-1h-64 等工具将元素设置为固定高度。

¥Use utilities like h-px, h-1, and h-64 to set an element to a fixed height.

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>

全高

¥Full height

使用 h-full 将元素的高度设置为其父元素的 100%,只要父元素具有已定义的高度。

¥Use h-full to set an element’s height to 100% of its parent, as long as the parent has a defined height.

<div class="h-48">
  <div class="h-full ...">
    <!-- This element will have a height of `12rem` (h-48) -->
  </div>
</div>

视口高度

¥Viewport height

使用 h-screen 使元素跨越视口的整个高度。

¥Use h-screen to make an element span the entire height of the viewport.

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

动态视口高度

¥Dynamic viewport height

使用 h-dvh 使元素跨越视口的整个高度,视口的高度会随着浏览器 UI 的扩展或收缩而变化。

¥Use h-dvh to make an element span the entire height of the viewport, which changes as the browser UI expands or contracts.

Scroll up and down in the viewport to hide/show the browser UI

tailwindcss.com

h-dvh

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

大视口高度

¥Large viewport height

使用 h-lvh 将元素的高度设置为视口的最大可能高度。这与 100vh 的行为相同。

¥Use h-lvh to set an element’s height to the largest possible height of the viewport. This behaves the same as 100vh.

Scroll up and down in the viewport to hide/show the browser UI

tailwindcss.com

h-lvh

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

小视口高度

¥Small viewport height

使用 h-svh 将元素的高度设置为视口的最小可能高度。

¥Use h-svh to set an element’s height to the smallest possible height of the viewport.

Scroll up and down in the viewport to hide/show the browser UI

tailwindcss.com

h-svh

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

有条件地应用

悬停、聚焦和其他状态

Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:h-full to only apply the h-full utility on hover.

<div class="h-8 hover:h-full">
  <!-- ... -->
</div>

For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.

断点和媒体查询

You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:h-full to apply the h-full utility at only medium screen sizes and above.

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

To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.


使用自定义值

¥Using custom values

自定义主题

¥Customizing your theme

默认情况下,Tailwind 的身高比例是 默认间距比例 以及一些特定于身高的附加值的组合。

¥By default, Tailwind’s height scale is a combination of the default spacing scale as well as some additional values specific to heights.

你可以通过编辑 tailwind.config.js 文件中的 theme.spacingtheme.extend.spacing 来自定义间距比例。

¥You can customize your spacing scale by editing theme.spacing or theme.extend.spacing in your tailwind.config.js file.

tailwind.config.js
module.exports = {
  theme: {
    extend: {
      spacing: {
        '128': '32rem',
      }
    }
  }
}

要单独自定义高度,请使用 tailwind.config.js 文件的 theme.height 部分。

¥To customize height separately, use the theme.height section of your tailwind.config.js file.

tailwind.config.js
module.exports = {
  theme: {
    extend: {
      height: {
        '128': '32rem',
      }
    }
  }
}

主题定制 文档中了解有关自定义默认主题的更多信息。

¥Learn more about customizing the default theme in the theme customization documentation.

任意值

¥Arbitrary values

If you need to use a one-off height value that doesn’t make sense to include in your theme, use square brackets to generate a property on the fly using any arbitrary value.

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

Learn more about arbitrary value support in the arbitrary values documentation.