Skip to content

Flex Wrap 弹性盒自动换行

用于控制 flex 项目如何换行的实用工具。

ClassProperties

基本用法

不换行

使用 flex-nowrap 来防止弹性项换行,导致不灵活的项在必要时溢出容器:

01
02
03
html
<div class="flex flex-nowrap">
  <div>01</div>
  <div>02</div>
  <div>03</div>
</div>

正常换行

使用 flex-wrap 允许伸缩项换行:

01
02
03
html
<div class="flex flex-wrap">
  <div>01</div>
  <div>02</div>
  <div>03</div>
</div>

反向换行

使用 flex-wrap-reverse 将 flex 项目以相反的方向包裹起来:

01
02
03
html
<div class="flex flex-wrap-reverse">
  <div>01</div>
  <div>02</div>
  <div>03</div>
</div>

有条件地应用

悬停,焦点和其他状态

Tailwind 允许您使用变体修饰符在不同状态下有条件地应用实用程序类。例如,使用 hover:flex-wrap-reverse 只在悬停时应用 flex-wrap-reverse 实用程序。

html
<div class="flex flex-wrap hover:flex-wrap-reverse">
  <!-- ... -->
</div>

要查看所有可用状态修饰符的完整列表,请查看悬停,焦点和其他状态文档。

断点和媒体查询

您还可以使用变体修饰符来定位媒体查询,如响应式断点、暗模式、偏好减少动作等。例如,使用 md:flex-wrap-reverse 仅在中等屏幕尺寸及以上应用 flex-wrap-reverse 实用程序。

html
<div class="flex flex-wrap md:flex-wrap-reverse">
  <!-- ... -->
</div>

要了解更多信息,请查看有关响应式设计深色模式其他媒体查询修改器的文档。

Released under the MIT License.