Tailwind CSS Flex Grow

2022-08-08 10:08 更新

Flex Grow

控制 flex 項(xiàng)目放大的功能類

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

Grow

使用 ?flex-grow? 允許一個(gè) flex 項(xiàng)目放大,以填充任何可用空間。


<div class="flex ...">
  <div class="flex-none w-16 h-16 ...">
    <!-- This item will not grow -->
  </div>
  <div class="flex-grow h-16 ...">
    <!-- This item will grow -->
  </div>
  <div class="flex-none w-16 h-16 ...">
    <!-- This item will not grow -->
  </div>
</div>

Don't grow

使用 ?flex-grow-0? 阻止一個(gè) flex 項(xiàng)目放大:


<div class="flex ...">
  <div class="flex-grow h-16 ...">
    <!-- This item will grow -->
  </div>
  <div class="flex-grow-0 h-16 ...">
    <!-- This item will not grow -->
  </div>
  <div class="flex-grow h-16 ...">
    <!-- This item will grow -->
  </div>
</div>

響應(yīng)式

要控制 flex 項(xiàng)目在特定斷點(diǎn)處的放大方式,請(qǐng)?jiān)谌魏维F(xiàn)有的功能類前添加 ?{screen}:? 前綴。例如,使用 ?md:flex-grow-0? 僅在中等及以上尺寸屏幕上應(yīng)用 ?flex-grow-0? 功能。

<div class="flex ...">
  <!-- ... -->
  <div class="flex-grow md:flex-grow-0 ...">
    Responsive flex item
  </div>
  <!-- ... -->
</div>

關(guān)于 Tailwind 的響應(yīng)式設(shè)計(jì)功能的更多信息,請(qǐng)查看 響應(yīng)式設(shè)計(jì) 文檔。

自定義

Grow Values

默認(rèn)情況下,Tailwind 提供了兩個(gè) ?flex-grow? 實(shí)用程序。您可以通過(guò)編輯 Tailwind 配置的 ?theme.flexGrow? 部分來(lái)更改、添加或刪除這些內(nèi)容。

  // tailwind.config.js
  module.exports = {
    theme: {
      flexGrow: {
        '0': 0,
       DEFAULT: 1,
       DEFAULT: 2,
       '1': 1,
      }
    }
  }

變體

默認(rèn)情況下, 針對(duì) flex grow 功能類,只生成 responsive 變體。

您可以通過(guò)修改您的 ?tailwind.config.js? 文件中的 ?variants ?部分中的 ?flexGrow ?屬性來(lái)控制為 flex grow 功能生成哪些變體。

例如,這個(gè)配置也將生成 hover and focus 變體:

  // tailwind.config.js
  module.exports = {
    variants: {
      extend: {
        // ...
       flexGrow: ['hover', 'focus'],
      }
    }
  }

禁用

如果您不打算在您的項(xiàng)目中使用 flex grow 功能,您可以通過(guò)在配置文件的 ?corePlugins ?部分將 ?flexGrow ?屬性設(shè)置為 ?false ?來(lái)完全禁用它們:

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


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)