尺寸
同时设置元素宽度和高度的工具。
¥Basic usage
¥Fixed sizes
使用 size-px
、size-1
和 size-64
等工具同时将元素设置为固定宽度和高度。
¥Use utilities like size-px
, size-1
, and size-64
to set an element to a fixed width and height at the same time.
<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
使用 size-full
将元素的宽度和高度设置为父容器宽度和高度的 100%。
¥Use size-full
to set an element’s width and height to be 100% of the parent container’s width and height.
<div class="h-56 p-2 ...">
<div class="size-full ...">size-full</div>
</div>
¥Resetting the size
如果你需要在特定条件下(例如在特定断点处)删除元素指定的宽度和高度,则 size-auto
工具会很有用:
¥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>
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.
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
默认情况下,Tailwind 的尺寸比例是 默认间距比例 以及一些特定于尺寸的附加值的组合。
¥By default, Tailwind’s size scale is a combination of the default spacing scale as well as some additional values specific to sizing.
你可以通过编辑 tailwind.config.js
文件中的 theme.spacing
或 theme.extend.spacing
来自定义间距比例。
¥You can customize your spacing scale by editing theme.spacing
or theme.extend.spacing
in your tailwind.config.js
file.
module.exports = {
theme: {
extend: {
spacing: {
'128': '32rem',
}
}
}
}
要单独自定义大小,请使用 tailwind.config.js
文件的 theme.size
部分。
¥To customize size separately, use the theme.size
section of your tailwind.config.js
file.
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.