返回介绍

Size

发布于 2024-07-30 22:16:07 字数 33102 浏览 0 评论 0 收藏 0

Utilities for setting the width and height of an element at the same time.

Quick reference

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

Basic usage

Fixed sizes

Use utilities like size-px, size-1, and size-64 to set an element to a fixed width and height at the same time.

size-16 size-20 size-24 size-32 size-40
<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>

Percentage sizes

Use size-full to set an element’s width and height to be 100% of the parent container’s width and height.

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

Resetting the size

The size-auto utility can be useful if you need to remove an element’s assigned width and height under a specific condition, like at a particular breakpoint:

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

Applying conditionally

Hover, focus, and other states

Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:size-full to only apply the size-full utility on hover.

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

For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.

Breakpoints and media queries

You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:size-full to apply the size-full utility at only medium screen sizes and above.

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

To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.


Using custom values

Customizing your theme

By default, Tailwind’s size scale is a combination of the default spacing scale as well as some additional values specific to sizing.

You can customize your spacing scale by editing theme.spacing or theme.extend.spacing in your tailwind.config.js file.

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

To customize size separately, use the theme.size section of your tailwind.config.js file.

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

Learn more about customizing the default theme in the theme customization documentation.

Arbitrary values

If you need to use a one-off size value that doesn’t make sense to include in your theme, use square brackets to generate a property on the fly using any arbitrary value.

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

Learn more about arbitrary value support in the arbitrary values documentation.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文