Skip to content

Height

<https://www.tailwindcss.cn/docs/height>

用法

ClassProperties
h-0height: 0px;
h-pxheight: 1px;
h-0.5height: 0.125rem;
h-1height: 0.25rem;
h-1.5height: 0.375rem;
h-2height: 0.5rem;
h-2.5height: 0.625rem;
h-3height: 0.75rem;
h-3.5height: 0.875rem;
h-4height: 1rem;
h-5height: 1.25rem;
h-6height: 1.5rem;
h-7height: 1.75rem;
h-8height: 2rem;
h-9height: 2.25rem;
h-10height: 2.5rem;
h-11height: 2.75rem;
h-12height: 3rem;
h-14height: 3.5rem;
h-16height: 4rem;
h-20height: 5rem;
h-24height: 6rem;
h-28height: 7rem;
h-32height: 8rem;
h-36height: 9rem;
h-40height: 10rem;
h-44height: 11rem;
h-48height: 12rem;
h-52height: 13rem;
h-56height: 14rem;
h-60height: 15rem;
h-64height: 16rem;
h-72height: 18rem;
h-80height: 20rem;
h-96height: 24rem;
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;

固定高度

使用 h-{number} 或 h-px 将元素设置为固定高度。

html
&lt;div class="h-96 ...">h-96&lt;/div>
&lt;div class="h-80 ...">h-80&lt;/div>
&lt;div class="h-64 ...">h-64&lt;/div>
&lt;div class="h-48 ...">h-48&lt;/div>
&lt;div class="h-40 ...">h-40&lt;/div>
&lt;div class="h-32 ...">h-32&lt;/div>
&lt;div class="h-24 ...">h-24&lt;/div>

全高

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

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

动态视口高度

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

大视口高度

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

小视口高度

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

断点和媒体查询

您还可以使用变体修饰符来定位媒体查询,例如响应断点、深色模式、首选减少运动等。例如,使用 md:h-full 仅在中等屏幕尺寸及以上屏幕尺寸上应用 h-full 实用程序。

共 20 个模块,1301 篇 Markdown 文档。