css教程网 css教程网365css.cn
公告为您打开互联网世界的窗户关于本站
首页/属性速查/布局与定位

place-items

align-items 与 justify-items 的合写,一行实现双向居中。

语法
place-items: <align-items> <justify-items>?
常用值
center / start / end / stretch
初始值
normal
继承
否

运行效果

示例改成别的值试试,差异一眼能看出来
查看代码
HTML
<div class="pi"><i>centered</i></div>
CSS
.pi { display: grid; place-items: center; width: 100%; height: 100px; background: #f6f8fc; border-radius: 10px; }
.pi i { padding: 8px 14px; border-radius: 7px; background: #2b57ff; color: #fff; font: 600 11px/1 ui-monospace, monospace; font-style: normal; }

使用要点

  • grid 与 flex 都能用。flex 容器里第二值会被忽略(flex 没有 justify-items)。