1. Flexbox 和 Grid
  2. place-content

Flexbox 和 Grid

place-content

用于控制内容如何同时对齐和对齐的工具。

样式
place-content-center
place-content: center;
place-content-start
place-content: start;
place-content-end
place-content: end;
place-content-between
place-content: space-between;
place-content-around
place-content: space-around;
place-content-evenly
place-content: space-evenly;
place-content-baseline
place-content: baseline;
place-content-stretch
place-content: stretch;

示例(Examples)

¥Examples

中心(Center)

¥Center

使用 place-content-center 在方块轴的中心打包物品:

¥Use place-content-center to pack items in the center of the block axis:

01
02
03
04
<div class="grid h-48 grid-cols-2 place-content-center gap-4 ...">
<div>01</div>
<div>02</div>
<div>03</div>
<div>04</div>
</div>

开始(Start)

¥Start

使用 place-content-start 将项目打包到块轴的起点:

¥Use place-content-start to pack items against the start of the block axis:

01
02
03
04
<div class="grid h-48 grid-cols-2 place-content-start gap-4 ...">
<div>01</div>
<div>02</div>
<div>03</div>
<div>04</div>
</div>

结尾(End)

¥End

使用 place-content-end 将项目打包到块轴的末端:

¥Use place-content-end to pack items against the end of the block axis:

01
02
03
04
<div class="grid h-48 grid-cols-2 place-content-end gap-4 ...">
<div>01</div>
<div>02</div>
<div>03</div>
<div>04</div>
</div>

之间的空间(Space between)

¥Space between

使用 place-content-between 沿块轴分布网格项,以便块轴上每行之间的空间相等:

¥Use place-content-between to distribute grid items along the block axis so that there is an equal amount of space between each row on the block axis:

01
02
03
04
<div class="grid h-48 grid-cols-2 place-content-between gap-4 ...">
<div>01</div>
<div>02</div>
<div>03</div>
<div>04</div>
</div>

周围空间(Space around)

¥Space around

使用 place-content-around 分布网格项,以便块轴上每行周围的空间相等:

¥Use place-content-around to distribute grid items such that there is an equal amount of space around each row on the block axis:

01
02
03
04
<div class="grid h-48 grid-cols-2 place-content-around gap-4 ...">
<div>01</div>
<div>02</div>
<div>03</div>
<div>04</div>
</div>

空间均匀(Space evenly)

¥Space evenly

使用 place-content-evenly 分布网格项,使它们在块轴上均匀分布:

¥Use place-content-evenly to distribute grid items such that they are evenly spaced on the block axis:

01
02
03
04
<div class="grid h-48 grid-cols-2 place-content-evenly gap-4 ...">
<div>01</div>
<div>02</div>
<div>03</div>
<div>04</div>
</div>

拉紧(Stretch)

¥Stretch

使用 place-content-stretch 沿块轴上的网格区域拉伸网格项:

¥Use place-content-stretch to stretch grid items along their grid areas on the block axis:

01
02
03
04
<div class="grid h-48 grid-cols-2 place-content-stretch gap-4 ...">
<div>01</div>
<div>02</div>
<div>03</div>
<div>04</div>
</div>

响应式设计(Responsive design)

¥Responsive design

place-content 工具前面使用断点变体如 md: 仅在 medium 屏幕尺寸及以上时应用工具:

<div class="grid place-content-start md:place-content-center ...">
<!-- ... -->
</div>

请参阅 变体文档 详细了解如何使用变体。

TailwindCSS v4.0 中文网 - 粤ICP备13048890号