使用
h-{number}
或
h-px
将元素设置为固定高度。
<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
将元素的高度设置为其父元素的 100%,前提是父元素具有定义的高度。
<div class="h-48">
<div class="h-full ...">
</div>
</div>
使用
h-screen
使元素跨越整个视窗高度。
<div class="h-screen">
</div>
使用
h-dvh
使元素跨越整个视窗高度,该高度会随着浏览器 UI 的扩展或收缩而改变。
<div class="h-dvh">
</div>
使用
h-lvh
将元素的高度设置为视窗的最大可能高度。这与
100vh
的行为相同。
<div class="h-lvh">
</div>
使用
h-svh
将元素的高度设置为视窗的最小高度。
<div class="h-svh">
</div>
Tailwind 允许您使用变体修饰符在不同状态下有条件地应用实用程序类。例如,使用
hover
:
h-full
仅在悬停时应用
h-full
实用程序。
<div class="h-8 hover:h-full">
</div>
有关所有可用状态修饰符的完整列表,请查看
悬停、焦点和其它状态
文档。
您还可以使用变体修饰符来定位媒体查询,例如响应式断点、暗模式、prefers-reduced-motion 等等。例如,使用
md:
h-full
仅在中等屏幕尺寸及以上时应用
h-full
实用程序。
<div class="h-8 md:h-full">
</div>
要了解更多信息,请查看有关
响应式设计
、
暗模式
和
其他媒体查询修饰符
的文档。
默认情况下,Tailwind 的高度比例尺是
默认间距比例尺
和一些特定于高度的附加值的组合。
您可以通过编辑
tailwind.config.js
文件中的
theme.spacing
或
theme.extend.spacing
来自定义间距比例尺。
tailwind.config.js
module.exports = {
theme: {
extend: {
spacing: {
'128': '32rem',
要单独自定义高度,请使用 tailwind.config.js
文件的 theme.height
部分。
tailwind.config.js
module.exports = {
theme: {
extend: {
height: {
'128': '32rem',