Tailwind CSS Justify Content

2022-08-08 10:05 更新

Justify Content

用于控制 flex 和 grid 項(xiàng)目如何沿著容器的主軸定位的功能類。

Class
Properties
justify-start justify-content: flex-start;
justify-end justify-content: flex-end;
justify-center justify-content: center;
justify-between justify-content: space-between;
justify-around justify-content: space-around;
justify-evenly justify-content: space-evenly;

Start

使用 ?justify-start? 讓項(xiàng)目沿著容器主軸的起點(diǎn)對(duì)齊。


<div class="flex justify-start ...">
  <div>1</div>
  <div>2</div>
  <div>3</div>
</div>

Center

使用 ?justify-center? 讓項(xiàng)目沿著容器主軸的中心點(diǎn)對(duì)齊。


<div class="flex justify-center ...">
  <div>1</div>
  <div>2</div>
  <div>3</div>
</div>

End

使用 ?justify-end? 讓項(xiàng)目沿著容器主軸的結(jié)束點(diǎn)對(duì)齊。


<div class="flex justify-end ...">
  <div>1</div>
  <div>2</div>
  <div>3</div>
</div>

Space between

使用 ?justify-between? 讓項(xiàng)目沿著容器主軸排列,并使每個(gè)項(xiàng)目之間的距離相等。


<div class="flex justify-between ...">
  <div>1</div>
  <div>2</div>
  <div>3</div>
</div>

Space around

使用 ?justify-around? 讓項(xiàng)目沿著容器主軸排列,并使每個(gè)項(xiàng)目?jī)蓚?cè)的距離相等。


<div class="flex justify-around ...">
  <div>1</div>
  <div>2</div>
  <div>3</div>
</div>

Space evenly

使用 ?justify-evenly? 讓項(xiàng)目沿著容器主軸排列,并使每個(gè)項(xiàng)目周圍的距離相等,但不像使用 ?justify-around? 時(shí)項(xiàng)目之間有雙倍的距離。


<div class="flex justify-evenly ...">
  <div>1</div>
  <div>2</div>
  <div>3</div>
</div>

響應(yīng)式

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

<div class="justify-start md:justify-between ...">
  <!-- ... -->
</div>

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

自定義

變體

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

您可以通過修改您的 ?tailwind.config.js? 文件中的 ?variants ?部分中的 ?justifyContent ?屬性來控制為 justify-content 功能生成哪些變體。

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

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

禁用

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

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


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

掃描二維碼

下載編程獅App

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

編程獅公眾號(hào)