你正在瀏覽的是 Tailwind CSS v2. 的技術文件
Tailwind CSS 的 GitHub

Align Content

Utilities for controlling how rows are positioned in multi-row flex and grid containers.

Default class reference

Class
屬性
content-centeralign-content: center;
content-startalign-content: flex-start;
content-endalign-content: flex-end;
content-betweenalign-content: space-between;
content-aroundalign-content: space-around;
content-evenlyalign-content: space-evenly;

Start

Use content-start to pack rows in a container against the start of the cross axis:

1
2
3
4
5
<div class="h-48 flex flex-wrap content-start ...">
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
  <div>5</div>
</div>

Center

Use content-center to pack rows in a container in the center of the cross axis:

1
2
3
4
5
<div class="h-48 flex flex-wrap content-center ...">
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
  <div>5</div>
</div>

End

Use content-end to pack rows in a container against the end of the cross axis:

1
2
3
4
5
<div class="h-48 flex flex-wrap content-end ...">
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
  <div>5</div>
</div>

Space between

Use content-between to distribute rows in a container such that there is an equal amount of space between each line:

1
2
3
4
5
<div class="h-48 flex flex-wrap content-between ...">
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
  <div>5</div>
</div>

Space around

Use content-around to distribute rows in a container such that there is an equal amount of space around each line:

1
2
3
4
5
<div class="h-48 flex flex-wrap content-around ...">
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
  <div>5</div>
</div>

Space evenly

Use content-evenly to distribute rows in a container such that there is an equal amount of space around each item, but also accounting for the doubling of space you would normally see between each item when using content-around:

1
2
3
4
5
<div class="h-48 flex flex-wrap content-evenly ...">
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
  <div>5</div>
</div>

Responsive

To control the alignment of flex content at a specific breakpoint, add a {screen}: prefix to any existing utility class. For example, use md:content-around to apply the content-around utility at only medium screen sizes and above.

<div class="content-start md:content-around ...">
  <!-- ... -->
</div>

更多有關 Tailwind 響應式設計功能的資訊,可參考 響應式設計 文件。

Customizing

Variants

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

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

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

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

Disabling

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

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