
弹性盒 & 网格
用于控制弹性子项如何增长和收缩的工具。
使用 flex-initial 允许弹性子项收缩但不增长,同时考虑其初始大小:
🌐 Use flex-initial to allow a flex item to shrink but not grow, taking into account its initial size:
<div class="flex">
<div class="flex-none w-14 ...">
01
</div>
<div class="flex-initial w-64 ...">
02
</div>
<div class="flex-initial w-32 ...">
03
</div>
</div>
使用 flex-1 允许弹性项目根据需要增长和缩小,而忽略其初始大小:
🌐 Use flex-1 to allow a flex item to grow and shrink as needed, ignoring its initial size:
<div class="flex">
<div class="flex-none w-14 ...">
01
</div>
<div class="flex-1 w-64 ...">
02
</div>
<div class="flex-1 w-32 ...">
03
</div>
</div>
使用 flex-auto 允许弹性项目根据初始尺寸进行增长和收缩:
🌐 Use flex-auto to allow a flex item to grow and shrink, taking into account its initial size:
<div class="flex ...">
<div class="flex-none w-14 ...">
01
</div>
<div class="flex-auto w-64 ...">
02
</div>
<div class="flex-auto w-32 ...">
03
</div>
</div>
使用 flex-none 防止弹性项目增长或缩小:
🌐 Use flex-none to prevent a flex item from growing or shrinking:
<div class="flex ...">
<div class="flex-none w-14 ...">
01
</div>
<div class="flex-none w-32 ...">
02
</div>
<div class="flex-1 ...">
03
</div>
</div>
Tailwind 允许你使用变体修饰符在不同状态下有条件地应用工具类。例如,使用hover:flex-1 仅在 hover 时应用 flex-1 工具。
<div class="flex-none hover:flex-1">
<!-- ... -->
</div>
有关所有可用状态修饰符的完整列表,请查看悬停、聚焦、以及其他状态 文档。
你还可以使用变体修饰符来定位媒体查询,例如响应式断点、暗黑模式、首选减少运动等。例如,使用 md:flex-1 仅在中等屏幕尺寸及以上时应用 flex-1 工具。
<div class="flex-none md:flex-1">
<!-- ... -->
</div>
要了解更多信息,请查看有关 响应式设计、暗黑模式、以及 其他媒体查询修饰符 的文档。
默认情况下,Tailwind 提供四个 flex 工具类。你可以通过编辑 tailwind.config.js 文件中的 theme.flex 或 theme.extend.flex 来自定义这些值。
🌐 By default, Tailwind provides four flex utilities. You can customize these values by editing theme.flex or theme.extend.flex in your tailwind.config.js file.
module.exports = {
theme: {
extend: {
flex: {
'2': '2 2 0%'
}
}
}
}
在主题自定义文档中了解有关自定义默认主题的更多信息。
🌐 Learn more about customizing the default theme in the theme customization documentation.
如果你需要使用一次性的 flex 值,而该值没有必要包含在你的主题中,请使用方括号动态生成属性,使用任意值。
<div class="flex-[2_2_0%]">
<!-- ... -->
</div>
在 任意值 文档中了解有关任意值支持的更多信息。