快速參考

類別
屬性
size-0寬度: 0px; 高度: 0px;
size-px寬度: 1px; 高度: 1px;
size-0.5寬度: 0.125rem; /* 2px */ 高度: 0.125rem; /* 2px */
size-1寬度: 0.25rem; /* 4px */ 高度: 0.25rem; /* 4px */
size-1.5寬度: 0.375rem; /* 6px */ 高度: 0.375rem; /* 6px */
size-2寬度: 0.5rem; /* 8px */ 高度: 0.5rem; /* 8px */
size-2.5寬度: 0.625rem; /* 10px */ 高度: 0.625rem; /* 10px */
size-3寬度: 0.75rem; /* 12px */ 高度: 0.75rem; /* 12px */
size-3.5寬度: 0.875rem; /* 14px */ 高度: 0.875rem; /* 14px */
size-4寬度: 1rem; /* 16px */ 高度: 1rem; /* 16px */
大小-5寬度: 1.25rem; /* 20px */ 高度: 1.25rem; /* 20px */
大小-6寬度: 1.5rem; /* 24px */ 高度: 1.5rem; /* 24px */
大小-7寬度: 1.75rem; /* 28px */ 高度: 1.75rem; /* 28px */
大小-8寬度: 2rem; /* 32px */ 高度: 2rem; /* 32px */
大小-9寬度: 2.25rem; /* 36px */ 高度: 2.25rem; /* 36px */
大小-10寬度: 2.5rem; /* 40px */ 高度: 2.5rem; /* 40px */
大小-11寬度: 2.75rem; /* 44px */ 高度: 2.75rem; /* 44px */
大小-12寬度: 3rem; /* 48px */ 高度: 3rem; /* 48px */
大小-14寬度: 3.5rem; /* 56px */ 高度: 3.5rem; /* 56px */
大小-16寬度: 4rem; /* 64px */ 高度: 4rem; /* 64px */
大小-20寬度: 5rem; /* 80px */ 高度: 5rem; /* 80px */
尺寸-24寬度: 6rem; /* 96px */ 高度: 6rem; /* 96px */
尺寸-28寬度: 7rem; /* 112px */ 高度: 7rem; /* 112px */
尺寸-32寬度: 8rem; /* 128px */ 高度: 8rem; /* 128px */
尺寸-36寬度: 9rem; /* 144px */ 高度: 9rem; /* 144px */
尺寸-40寬度: 10rem; /* 160px */ 高度: 10rem; /* 160px */
尺寸-44寬度: 11rem; /* 176px */ 高度: 11rem; /* 176px */
尺寸-48寬度: 12rem; /* 192px */ 高度: 12rem; /* 192px */
尺寸-52寬度: 13rem; /* 208px */ 高度: 13rem; /* 208px */
尺寸-56寬度: 14rem; /* 224px */ 高度: 14rem; /* 224px */
尺寸-60寬度15rem /* 240px */ 高度15rem /* 240px */
size-64寬度16rem /* 256px */ 高度16rem /* 256px */
size-72寬度18rem /* 288px */ 高度18rem /* 288px */
size-80寬度20rem /* 320px */ 高度20rem /* 320px */
size-96寬度24rem /* 384px */ 高度24rem /* 384px */
size-auto寬度auto 高度auto
size-1/2寬度50% 高度50%
size-1/3寬度33.333333% 高度33.333333%
size-2/3寬度66.666667% 高度66.666667%
size-1/4寬度25% 高度25%
size-2/4寬度50% 高度50%
size-3/4寬度75% 高度75%
size-1/5寬度20% 高度20%
size-2/5寬度: 40%; 高度: 40%;
size-3/5寬度: 60%; 高度: 60%;
size-4/5寬度: 80%; 高度: 80%;
size-1/6寬度: 16.666667%; 高度: 16.666667%;
size-2/6寬度33.333333% 高度33.333333%
size-3/6寬度50% 高度50%
size-4/6寬度66.666667% 高度66.666667%
size-5/6寬度: 83.333333%; 高度: 83.333333%;
size-1/12寬度: 8.333333%; 高度: 8.333333%;
size-2/12寬度: 16.666667%; 高度: 16.666667%;
size-3/12寬度25% 高度25%
size-4/12寬度33.333333% 高度33.333333%
size-5/12寬度: 41.666667%; 高度: 41.666667%;
size-6/12寬度50% 高度50%
size-7/12寬度: 58.333333%; 高度: 58.333333%;
size-8/12寬度66.666667% 高度66.666667%
size-9/12寬度75% 高度75%
size-10/12寬度: 83.333333%; 高度: 83.333333%;
size-11/12寬度: 91.666667%; 高度: 91.666667%;
size-full寬度: 100%; 高度: 100%;
size-min寬度: min-content; 高度: min-content;
size-max寬度: max-content; 高度: max-content;
size-fit寬度: fit-content; 高度: fit-content;

基本用法

固定大小

使用 size-{number}size-px 同時設定元素的固定寬度和高度。

大小-16
大小-20
尺寸-24
<div class="size-16 ...">size-16</div>
<div class="size-20 ...">size-20</div>
<div class="size-24 ...">size-24</div>
<div class="size-32 ...">size-32</div>
<div class="size-40 ...">size-40</div>

百分比大小

使用 size-full 設定元素的寬度和高度為父容器寬度和高度的 100%。

size-full
<div class="h-56 p-2 ...">
  <div class="size-full ...">size-full</div>
</div>

重設大小

如果你需要在特定條件下移除元素指定的寬度和高度,例如在特定斷點處,size-auto 工具程式會很有用

<div class="size-full md:size-auto">
  <!-- ... -->
</div>

有條件地套用

滑鼠懸停、焦點和其他狀態

Tailwind 讓你可以在不同狀態下使用變體修改器有條件地套用工具程式類別。例如,使用 hover:size-full 僅在滑鼠懸停時套用 size-full 工具程式。

<div class="size-48 hover:size-full">
  <!-- ... -->
</div>

如需所有可用的狀態修改器的完整清單,請查看 懸停、焦點及其他狀態 文件。

斷點和媒體查詢

您也可以使用變異修改器來鎖定媒體查詢,例如回應式斷點、深色模式、偏好減少動畫等。例如,使用 md:size-full 僅在中型螢幕尺寸及以上套用 size-full 實用程式。

<div class="size-48 md:size-full">
  <!-- ... -->
</div>

如需深入了解,請查看 回應式設計 深色模式 其他媒體查詢修改器 的文件。


使用自訂值

自訂您的主題

預設情況下,Tailwind 的大小比例是 預設間距比例 與一些特定於大小調整的其他數值的組合。

您可以透過編輯 tailwind.config.js 檔案中的 theme.spacingtheme.extend.spacing 來自訂您的間距比例。

tailwind.config.js
module.exports = {
  theme: {
    extend: {
      spacing: {
        '128': '32rem',
      }
    }
  }
}

若要個別自訂大小,請使用 tailwind.config.js 檔案中的 theme.size 區段。

tailwind.config.js
module.exports = {
  theme: {
    extend: {
      size: {
        '128': '32rem',
      }
    }
  }
}

主題自訂 文件中進一步了解如何自訂預設主題。

任意值

如果您需要使用一次性的 size 值,而將其包含在主題中沒有意義,請使用方括號來使用任何任意值動態產生屬性。

<div class="size-[32rem]">
  <!-- ... -->
</div>

任意值 文件中進一步了解任意值支援。