1. 弹性盒子与网格
  2. 网格自动列

弹性盒子与网格

grid-auto-columns

控制隐式创建的网格列大小的工具类。

ClassStyles
auto-cols-auto
grid-auto-columns: auto;
auto-cols-min
grid-auto-columns: min-content;
auto-cols-max
grid-auto-columns: max-content;
auto-cols-fr
grid-auto-columns: minmax(0, 1fr);
auto-cols-(<custom-property>)
grid-auto-columns: var(<custom-property>);
auto-cols-[<value>]
grid-auto-columns: <value>;

示例

基础示例

使用 auto-cols-minauto-cols-max 等工具类来控制隐式创建的网格列的大小:

<div class="grid auto-cols-max grid-flow-col">
<div>01</div>
<div>02</div>
<div>03</div>
</div>

使用自定义值

Use the auto-cols-[<value>] syntax to set the 隐式创建的网格列的大小 based on a completely custom value:

<div class="auto-cols-[minmax(0,2fr)] ...">
<!-- ... -->
</div>

For CSS variables, you can also use the auto-cols-(<custom-property>) syntax:

<div class="auto-cols-(--my-auto-cols) ...">
<!-- ... -->
</div>

This is just a shorthand for auto-cols-[var(<custom-property>)] that adds the var() function for you automatically.

响应式设计

Prefix a grid-auto-columns utility with a breakpoint variant like md: to only apply the utility at medium screen sizes and above:

<div class="grid grid-flow-col auto-cols-max md:auto-cols-min ...">
<!-- ... -->
</div>

Learn more about using variants in the variants documentation.