- 入门
- 核心概念
- 定制
- Base Styles
- 布局
- Flexbox & Grid
- Flex Basis
- Flex Direction
- Flex Wrap
- Flex
- Flex Grow
- Flex Shrink
- Order
- Grid Template Columns
- Grid Column Start / End
- Grid Template Rows
- Grid Row Start / End
- Grid Auto Flow
- Grid Auto Columns
- Grid Auto Rows
- Gap
- Justify Content
- Justify Items
- Justify Self
- Align Content
- Align Items
- Align Self
- Place Content
- Place Items
- Place Self
- 间隔
- 尺寸
- 排版
- Font Family
- Font Size
- Font Smoothing
- Font Style
- Font Weight
- Font Variant Numeric
- Letter Spacing
- Line Clamp
- Line Height
- List Style Image
- List Style Position
- List Style Type
- Text Align
- Text Color
- Text Decoration
- Text Decoration Color
- Text Decoration Style
- Text Decoration Thickness
- Text Underline Offset
- Text Transform
- Text Overflow
- Text Wrap
- Text Indent
- Vertical Align
- Whitespace
- Word Break
- Hyphens
- Content
- 背景
- 边框
- Effects
- Filters
- 表格 Tables
- Transitions & Animation
- Transforms
- Interactivity
- SVG
- Accessibility
- 其他
- Install Tailwind CSS using PostCSS
- Framework Guides
- Try Tailwind CSS using the Play CDN
- Install Tailwind CSS with Next.js
- Install Tailwind CSS with Laravel
- Install Tailwind CSS with Vite
- Install Tailwind CSS with Nuxt
- Install Tailwind CSS with Gatsby
- Install Tailwind CSS with SolidJS
- Install Tailwind CSS with SvelteKit
- Install Tailwind CSS with Angular
- Install Tailwind CSS with Ruby on Rails
- Install Tailwind CSS with Remix
- Install Tailwind CSS with Phoenix
- Install Tailwind CSS with Parcel
- Install Tailwind CSS with Symfony
- Install Tailwind CSS with Meteor
- Install Tailwind CSS with Create React App
- Install Tailwind CSS with Adonis
- Install Tailwind CSS With Ember.js
- Install Tailwind CSS with Astro
- Install Tailwind CSS with Qwik
- Install Tailwind CSS with Rspack
Max-Height
Utilities for setting the maximum height of an element.
Quick reference
Class | Properties |
---|---|
max-h-0 | max-height: 0px; |
max-h-px | max-height: 1px; |
max-h-0.5 | max-height: 0.125rem; /* 2px */ |
max-h-1 | max-height: 0.25rem; /* 4px */ |
max-h-1.5 | max-height: 0.375rem; /* 6px */ |
max-h-2 | max-height: 0.5rem; /* 8px */ |
max-h-2.5 | max-height: 0.625rem; /* 10px */ |
max-h-3 | max-height: 0.75rem; /* 12px */ |
max-h-3.5 | max-height: 0.875rem; /* 14px */ |
max-h-4 | max-height: 1rem; /* 16px */ |
max-h-5 | max-height: 1.25rem; /* 20px */ |
max-h-6 | max-height: 1.5rem; /* 24px */ |
max-h-7 | max-height: 1.75rem; /* 28px */ |
max-h-8 | max-height: 2rem; /* 32px */ |
max-h-9 | max-height: 2.25rem; /* 36px */ |
max-h-10 | max-height: 2.5rem; /* 40px */ |
max-h-11 | max-height: 2.75rem; /* 44px */ |
max-h-12 | max-height: 3rem; /* 48px */ |
max-h-14 | max-height: 3.5rem; /* 56px */ |
max-h-16 | max-height: 4rem; /* 64px */ |
max-h-20 | max-height: 5rem; /* 80px */ |
max-h-24 | max-height: 6rem; /* 96px */ |
max-h-28 | max-height: 7rem; /* 112px */ |
max-h-32 | max-height: 8rem; /* 128px */ |
max-h-36 | max-height: 9rem; /* 144px */ |
max-h-40 | max-height: 10rem; /* 160px */ |
max-h-44 | max-height: 11rem; /* 176px */ |
max-h-48 | max-height: 12rem; /* 192px */ |
max-h-52 | max-height: 13rem; /* 208px */ |
max-h-56 | max-height: 14rem; /* 224px */ |
max-h-60 | max-height: 15rem; /* 240px */ |
max-h-64 | max-height: 16rem; /* 256px */ |
max-h-72 | max-height: 18rem; /* 288px */ |
max-h-80 | max-height: 20rem; /* 320px */ |
max-h-96 | max-height: 24rem; /* 384px */ |
max-h-none | max-height: none; |
max-h-full | max-height: 100%; |
max-h-screen | max-height: 100vh; |
max-h-svh | max-height: 100svh; |
max-h-lvh | max-height: 100lvh; |
max-h-dvh | max-height: 100dvh; |
max-h-min | max-height: min-content; |
max-h-max | max-height: max-content; |
max-h-fit | max-height: fit-content; |
Basic usage
Setting the maximum height
Set the maximum height of an element using max-h-*
utilities.
<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 class="h-full max-h-full ...">max-h-full</div>
</div>
Applying conditionally
Hover, focus, and other states
Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:max-h-screen
to only apply the max-h-screen
utility on hover.
<div class="h-48 max-h-full hover:max-h-screen">
<!-- ... -->
</div>
For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.
Breakpoints and media queries
You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:max-h-screen
to apply the max-h-screen
utility at only medium screen sizes and above.
<div class="h-48 max-h-full md:max-h-screen">
<!-- ... -->
</div>
To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.
Using custom values
Customizing your theme
By default, Tailwind’s maximum height scale is a combination of the default spacing scale as well as some additional values specific to heights.
You can customize your spacing scale by editing theme.spacing
or theme.extend.spacing
in your tailwind.config.js
file.
module.exports = {
theme: {
extend: {
spacing: {
'128': '32rem',
}
}
}
}
To customize max-height
separately, use the theme.minHeight
section of your tailwind.config.js
file.
module.exports = {
theme: {
extend: {
maxHeight: {
'128': '32rem',
}
}
}
}
Learn more about customizing the default theme in the theme customization documentation.
Arbitrary values
If you need to use a one-off max-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="max-h-[220px]">
<!-- ... -->
</div>
Learn more about arbitrary value support in the arbitrary values documentation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论