
弹性盒 & 网格
用于控制元素在网格列中大小和位置的实用工具。
使用 col-span-* 工具使一个元素跨越 n 列。
🌐 Use the col-span-* utilities to make an element span n columns.
<div class="grid grid-cols-3 gap-4">
<div class="...">01</div>
<div class="...">02</div>
<div class="...">03</div>
<div class="col-span-2 ...">04</div>
<div class="...">05</div>
<div class="...">06</div>
<div class="col-span-2 ...">07</div>
</div>
使用 col-start-* 和 col-end-* 工具使元素从第 nth 网格线开始或结束。也可以将它们与 col-span-* 工具结合使用,以跨越特定数量的列。
🌐 Use the col-start-* and col-end-* utilities to make an element start or end at the nth grid line. These can also be combined with the col-span-* utilities to span a specific number of columns.
请注意,CSS 网格线从 1 开始,而不是从 0 开始,因此在一个 6 列的网格中,全宽元素将从第 1 条线开始,到第 7 条线结束。
🌐 Note that CSS grid lines start at 1, not 0, so a full-width element in a 6-column grid would start at line 1 and end at line 7.
<div class="grid grid-cols-6 gap-4">
<div class="col-start-2 col-span-4 ...">01</div>
<div class="col-start-1 col-end-3 ...">02</div>
<div class="col-end-7 col-span-2 ...">03</div>
<div class="col-start-1 col-end-7 ...">04</div>
</div>
Tailwind 允许你使用变体修饰符在不同状态下有条件地应用工具类。例如,使用hover:col-span-6 仅在 hover 时应用 col-span-6 工具。
<div class="col-span-2 hover:col-span-6">
<!-- ... -->
</div>
有关所有可用状态修饰符的完整列表,请查看悬停、聚焦、以及其他状态 文档。
你还可以使用变体修饰符来定位媒体查询,例如响应式断点、暗黑模式、首选减少运动等。例如,使用 md:col-span-6 仅在中等屏幕尺寸及以上时应用 col-span-6 工具。
<div class="col-span-2 md:col-span-6">
<!-- ... -->
</div>
要了解更多信息,请查看有关 响应式设计、暗黑模式、以及 其他媒体查询修饰符 的文档。
默认情况下,Tailwind 包含用于处理最多 12 列网格的网格列工具。你可以通过自定义 Tailwind 主题配置中的 gridColumn、gridColumnStart 和 gridColumnEnd 部分来更改、添加或删除这些工具。
🌐 By default, Tailwind includes grid-column utilities for working with grids with up to 12 columns. You change, add, or remove these by customizing the gridColumn, gridColumnStart, and gridColumnEnd sections of your Tailwind theme config.
要添加新的 col-* 工具,请自定义 Tailwind 主题配置中的 gridColumn 部分:
🌐 To add new col-* utilities, customize the gridColumn section of your Tailwind theme config:
module.exports = {
theme: {
extend: {
gridColumn: {
'span-16': 'span 16 / span 16',
}
}
}
}
我们在内部将其用于我们的 col-span-* 工具。请注意,由于这是直接配置 grid-column 简写属性,我们在值名称中直接包含了 span 这个词,它不会自动内置到类名中。这意味着你可以自由添加任何你想要的条目——它们不必仅限于 span 工具。
🌐 We use this internally for our col-span-* utilities. Note that since this configures the grid-column shorthand property directly, we include the word span directly in the value name, it’s not baked into the class name automatically. That means you are free to add entries that do whatever you want here — they don’t just have to be span utilities.
要添加新的 col-start-* 工具,请自定义 Tailwind 主题配置中的 gridColumnStart 部分:
🌐 To add new col-start-* utilities, customize the gridColumnStart section of your Tailwind theme config:
module.exports = {
theme: {
extend: {
gridColumnStart: {
'13': '13',
'14': '14',
'15': '15',
'16': '16',
'17': '17',
}
}
}
}
要添加新的 col-end-* 工具,请自定义 Tailwind 主题配置中的 gridColumnEnd 部分:
🌐 To add new col-end-* utilities, customize the gridColumnEnd section of your Tailwind theme config:
module.exports = {
theme: {
extend: {
gridColumnEnd: {
'13': '13',
'14': '14',
'15': '15',
'16': '16',
'17': '17',
}
}
}
}
在主题自定义文档中了解有关自定义默认主题的更多信息。
🌐 Learn more about customizing the default theme in the theme customization documentation.
如果你需要使用一次性的 grid column 值,而该值没有必要包含在你的主题中,请使用方括号动态生成属性,使用任意值。
<div class="col-[16_/_span_16]">
<!-- ... -->
</div>
在 任意值 文档中了解有关任意值支持的更多信息。