「及時」模式:全新世代的 Tailwind CSS
Tailwind CSS on GitHub

Max-Height

Utilities for setting the maximum height of an element

Default class reference

Class
屬性
max-h-0max-height: 0px;
max-h-pxmax-height: 1px;
max-h-0.5max-height: 0.125rem;
max-h-1max-height: 0.25rem;
max-h-1.5max-height: 0.375rem;
max-h-2max-height: 0.5rem;
max-h-2.5max-height: 0.625rem;
max-h-3max-height: 0.75rem;
max-h-3.5max-height: 0.875rem;
max-h-4max-height: 1rem;
max-h-5max-height: 1.25rem;
max-h-6max-height: 1.5rem;
max-h-7max-height: 1.75rem;
max-h-8max-height: 2rem;
max-h-9max-height: 2.25rem;
max-h-10max-height: 2.5rem;
max-h-11max-height: 2.75rem;
max-h-12max-height: 3rem;
max-h-14max-height: 3.5rem;
max-h-16max-height: 4rem;
max-h-20max-height: 5rem;
max-h-24max-height: 6rem;
max-h-28max-height: 7rem;
max-h-32max-height: 8rem;
max-h-36max-height: 9rem;
max-h-40max-height: 10rem;
max-h-44max-height: 11rem;
max-h-48max-height: 12rem;
max-h-52max-height: 13rem;
max-h-56max-height: 14rem;
max-h-60max-height: 15rem;
max-h-64max-height: 16rem;
max-h-72max-height: 18rem;
max-h-80max-height: 20rem;
max-h-96max-height: 24rem;
max-h-fullmax-height: 100%;
max-h-screenmax-height: 100vh;

Usage

Set the maximum height of an element using the max-h-full or max-h-screen utilities.

.max-h-full
<div class="h-24 ...">
  <div class="h-48 max-h-full ...">
    .max-h-full
  </div>
</div>

Responsive

To control the max-height of an element at a specific breakpoint, add a {screen}: prefix to any existing max-height utility.

<div class="h-48 max-h-full md:max-h-screen ...">
  <span>Target</span>
</div>

For more information about Tailwind’s responsive design features, check out the Responsive Design documentation.


Customizing

Max-height scale

Customize Tailwind’s default max-height scale in the theme.maxHeight section of your tailwind.config.js file.

  // tailwind.config.js
  module.exports = {
    theme: {
      maxHeight: {
+       '0': '0',
+       '1/4': '25%',
+       '1/2': '50%',
+       '3/4': '75%',
+       'full': '100%',
      }
    }
  }

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

Variants

默認情況下, 只有 響應式 的 max-height 變化模式 (variants) 會產生。

tailwind.config.jsvariants 區塊中變更 maxHeight 屬性來決定有哪些變化模式會生成。

舉個例子來說,這個設定將會生成 響應式 和 hover 的變化模式。

  // tailwind.config.js
  module.exports = {
    variants: {
      extend: {
        // ...
+       maxHeight: ['responsive', 'hover'],
      }
    }
  }

Disabling

如果你不打算在專案中使用 max-height 功能,可以在你的設定檔裡的 corePlugins 屬性中將 maxHeight 設定為 false 來停用功能:

  // tailwind.config.js
  module.exports = {
    corePlugins: {
      // ...
+     maxHeight: false,
    }
  }