Tailwind CSS Place Self

2022-08-08 10:04 更新

Place Self

用于同時(shí)控制單個(gè)項(xiàng)目如何在水平和垂直方向上對(duì)齊的功能類(lèi)

Class
Properties
place-self-auto place-self: auto;
place-self-start place-self: start;
place-self-end place-self: end;
place-self-center place-self: center;
place-self-stretch place-self: stretch;

Auto

使用 ?place-self-auto? 根據(jù)容器的 ?place-items? 屬性的值來(lái)對(duì)齊一個(gè)項(xiàng)目:


<div class="grid grid-cols-3 gap-2 ...">
  <div>1</div>
  <div class="place-self-auto ...">2</div>
  <div>3</div>
  <div>4</div>
  <div>5</div>
  <div>6</div>
</div>

Start

使用 ?place-self-start? 將一個(gè)項(xiàng)目對(duì)齊兩個(gè)軸的起點(diǎn):


<div class="grid grid-cols-3 gap-2 ...">
  <div>1</div>
  <div class="place-self-start ...">2</div>
  <div>3</div>
  <div>4</div>
  <div>5</div>
  <div>6</div>
</div>

Center

使用 ?place-self-center? 將一個(gè)項(xiàng)目對(duì)齊兩個(gè)軸的中心:


<div class="grid grid-cols-3 gap-2 ...">
  <div>1</div>
  <div class="place-self-center ...">2</div>
  <div>3</div>
  <div>4</div>
  <div>5</div>
  <div>6</div>
</div>

End

使用 ?place-self-end? 將一個(gè)項(xiàng)目對(duì)齊兩個(gè)軸的終點(diǎn):


<div class="grid grid-cols-3 gap-2 ...">
  <div>1</div>
  <div class="place-self-end ...">2</div>
  <div>3</div>
  <div>4</div>
  <div>5</div>
  <div>6</div>
</div>

Stretch

使用 ?place-self-stretch? 沿著兩個(gè)軸拉伸一個(gè)項(xiàng)目:


<div class="grid grid-cols-3 gap-2 ...">
  <div>1</div>
  <div class="place-self-stretch ...">2</div>
  <div>3</div>
  <div>4</div>
  <div>5</div>
  <div>6</div>
</div>

響應(yīng)式

要在特定的斷點(diǎn)放置項(xiàng)目,可以在任何現(xiàn)有的 ?place-self? 功能類(lèi)前添加 ?{screen}:? 前綴。例如,使用 ?md:place-self-end? 來(lái)僅在中等尺寸及以上的屏幕應(yīng)用 ?place-self-end? 功能。

<div class="place-self-start md:place-self-end">
  <!-- ... -->
</div>

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

自定義

變體

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

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

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

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

禁用

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

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


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

掃描二維碼

下載編程獅App

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

編程獅公眾號(hào)