1. 弹性盒 & 网格
  2. 弹性增长

Quick reference

Class
Properties
growflex-grow: 1;
grow-0flex-grow: 0;

基本用法

¥Basic usage

增长

¥Grow

使用 grow 允许弹性项目增长以填充任何可用空间:

¥Use grow to allow a flex item to grow to fill any available space:

01
02
03
<div class="flex ...">
  <div class="flex-none w-14 h-14 ...">
    01
  </div>
  <div class="grow h-14 ...">
    02
  </div>
  <div class="flex-none w-14 h-14 ...">
    03
  </div>
</div>

不要增长

¥Don’t grow

使用 grow-0 来防止弹性项目增长:

¥Use grow-0 to prevent a flex item from growing:

01
02
<div class="flex ...">
  <div class="grow h-14 ...">
    01
  </div>
  <div class="grow-0 h-14 ...">
    02
  </div>
  <div class="grow h-14 ...">
    03
  </div>
</div>

有条件地应用

悬停、聚焦和其他状态

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

<div class="grow hover:grow-0">
  <!-- ... -->
</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:grow-0 to apply the grow-0 utility at only medium screen sizes and above.

<div class="grow md:grow-0">
  <!-- ... -->
</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 提供两个 grow 工具。你可以通过编辑 tailwind.config.js 文件中的 theme.flexGrowtheme.extend.flexGrow 来自定义这些值。

¥By default, Tailwind provides two grow utilities. You can customize these values by editing theme.flexGrow or theme.extend.flexGrow in your tailwind.config.js file.

tailwind.config.js
module.exports = {
  theme: {
    extend: {
      flexGrow: {
        2: '2'
      }
    }
  }
}

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

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

任意值

¥Arbitrary values

If you need to use a one-off flex-grow 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="grow-[2]">
  <!-- ... -->
</div>

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