1. 弹性盒子与网格
  2. 内容放置

弹性盒子与网格

place-content

用于控制内容在块轴上如何对齐和定位的工具。

ClassStyles
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;

示例

居中

使用 place-content-center 将项目打包在块轴的中心:

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>

开始

使用 place-content-start 将项目打包在块轴的开始位置:

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>

结束

使用 place-content-end 将项目打包在块轴的结束位置:

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>

行间距

使用 place-content-between 沿块轴分布网格项目,使每一行之间的间距相等:

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>

环绕

使用 place-content-around 来分配网格项目,使每行周围的间距相等:

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>

均匀间距

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

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>

拉伸

使用 place-content-stretch 在块轴上拉伸网格项目:

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>

响应式设计

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

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

Learn more about using variants in the variants documentation.