Skip to content

Flex Grow 弹性盒增长

控制 flex 项目如何增长的实用工具。

ClassProperties

基本用法

Grow 增长

使用 grow 来允许伸缩项增长以填充任何可用空间:

01
02
03
html
<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>

不增长

使用 grow-0 来防止 flex 项目的扩展:

01
02
html
<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 允许您使用变体修饰符在不同状态下有条件地应用实用程序类。例如,使用 hover:grow-0 只在悬停时应用 grow-0 实用程序。

html
<div class="grow hover:grow-0">
  <!-- ... -->
</div>

要查看所有可用状态修饰符的完整列表,请查看悬停,焦点和其他状态文档。

断点和媒体查询

您还可以使用变体修饰符来定位媒体查询,如响应式断点、暗模式、偏好减少动作等。例如,使用 md:grow-0 仅在中等屏幕尺寸及以上应用 grow-0 实用程序。

html
<div class="grow md:grow-0">
  <!-- ... -->
</div>

要了解更多信息,请查看有关响应式设计深色模式其他媒体查询修改器的文档。

使用自定义值

自定义您的主题

默认情况下,Tailwind 提供了两个 grow 实用程序。您可以通过编辑您的 tailwind.config.js 文件中的 theme.flexGrowtheme.extend.flexGrow 来自定义这些值。

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

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

任意值

如果您需要使用一次性 flex-grow 值,而这个值在您的主题中没有意义,可以使用方括号来使用任意值动态生成属性。

html
<div class="grow-[2]">
  <!-- ... -->
</div>

了解有关任意值支持的更多信息,请参阅任意值文档。

Released under the MIT License.