用于控制 flex 项目放大和缩小的功能类。
Items don't grow when there's extra space
Items shrink if possible when needed
<div class="flex">
<div class="flex-initial ...">
<!-- Won't grow, but will shrink if needed -->
</div>
<div class="flex-initial ...">
<!-- Won't grow, but will shrink if needed -->
</div>
<div class="flex-initial ...">
<!-- Won't grow, but will shrink if needed -->
</div>
</div>
Default behavior
With .flex-1
<div class="flex">
<div class="flex-1 ...">
<!-- Will grow and shrink as needed without taking initial size into account -->
</div>
<div class="flex-1 ...">
<!-- Will grow and shrink as needed without taking initial size into account -->
</div>
<div class="flex-1 ...">
<!-- Will grow and shrink as needed without taking initial size into account -->
</div>
</div>
Default behavior
With .flex-auto
<div class="flex ...">
<div class="flex-auto ...">
<!-- Will grow and shrink as needed taking initial size into account -->
</div>
<div class="flex-auto ...">
<!-- Will grow and shrink as needed taking initial size into account -->
</div>
<div class="flex-auto ...">
<!-- Will grow and shrink as needed taking initial size into account -->
</div>
</div>
<div class="flex ...">
<div class="flex-1 ...">
<!-- Will grow and shrink as needed -->
</div>
<div class="flex-none ...">
<!-- Will grow and shrink as needed taking initial size into account -->
</div>
<div class="flex-1 ...">
<!-- Will grow and shrink as needed -->
</div>
</div>
要控制 flex 项目在特定断点处的放大和缩小方式,可在任何现有的功能类产添加 {screen}:
前缀。例如,使用 md:flex-1
仅在中等尺寸及以上的屏幕应用 flex-1
功能。
<div class="flex ...">
<!-- ... -->
<div class="flex-none md:flex-1 ...">
Responsive flex item
</div>
<!-- ... -->
</div>
关于 Tailwind 的响应式设计功能的更多信息,请查看 响应式设计 文档。
默认情况下,Tailwind 提供了四个 flex
功能类。您可以通过编辑您的 Tailwind 配置的 theme.flex
部分来改变、添加或删除这些功能类。
// tailwind.config.js
module.exports = {
theme: {
flex: {
'1': '1 1 0%',
auto: '1 1 auto',
- initial: '0 1 auto',
+ inherit: 'inherit',
none: 'none',
+ '2': '2 2 0%',
}
}
}
默认情况下, 针对 flex 功能类,只生成 responsive 变体。
您可以通过修改您的 tailwind.config.js
文件中的 variants
部分中的 flex
属性来控制为 flex 功能生成哪些变体。
例如,这个配置也将生成 hover and focus 变体:
// tailwind.config.js
module.exports = {
variants: {
extend: {
// ...
+ flex: ['hover', 'focus'],
}
}
}
如果您不打算在您的项目中使用 flex 功能,您可以通过在配置文件的 corePlugins
部分将 flex
property to false
in the corePlugins
section of your config file:
// tailwind.config.js
module.exports = {
corePlugins: {
// ...
+ flex: false,
}
}