弹性盒 & 网格
用于控制网格和 flexbox 项目之间的间距的工具。
¥Basic usage
¥Setting the gap between elements
使用 gap-*
工具更改网格和 Flexbox 布局中行和列之间的间隙。
¥Use the gap-*
utilities to change the gap between both rows and columns in grid and flexbox layouts.
<div class="grid gap-4 grid-cols-2">
<div>01</div>
<div>02</div>
<div>03</div>
<div>04</div>
</div>
¥Changing row and column gaps independently
使用 gap-x-*
和 gap-y-*
工具独立更改列和行之间的间隙。
¥Use the gap-x-*
and gap-y-*
utilities to change the gap between columns and rows independently.
<div class="grid gap-x-8 gap-y-4 grid-cols-3">
<div>01</div>
<div>02</div>
<div>03</div>
<div>04</div>
<div>05</div>
<div>06</div>
</div>
Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:gap-6
to only apply the gap-6
utility on hover.
<div class="grid gap-4 hover:gap-6">
<!-- ... -->
</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:gap-6
to apply the gap-6
utility at only medium screen sizes and above.
<div class="grid gap-4 md:gap-6">
<!-- ... -->
</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 的间隙比例使用 默认间距比例。你可以通过编辑 tailwind.config.js
文件中的 theme.spacing
或 theme.extend.spacing
来自定义间距比例。
¥By default, Tailwind’s gap scale uses the default spacing scale. 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: {
'11': '2.75rem',
}
}
}
}
或者,你可以通过编辑 tailwind.config.js
文件中的 theme.gap
或 theme.extend.gap
来自定义间隙比例。
¥Alternatively, you can customize just the gap scale by editing theme.gap
or theme.extend.gap
in your tailwind.config.js
file.
module.exports = {
theme: {
extend: {
gap: {
'11': '2.75rem',
}
}
}
}
在 主题定制 文档中了解有关自定义默认主题的更多信息。
¥Learn more about customizing the default theme in the theme customization documentation.
¥Arbitrary values
If you need to use a one-off gap
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="grid gap-[2.75rem]">
<!-- ... -->
</div>
Learn more about arbitrary value support in the arbitrary values documentation.