<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.grid-centering {
display:grid ;
justify-content: center;
align-items: center;
height: 100px;
}
</style>
</head>
<body>
<div class="grid-centering">
<div class="child">Centered content.</div>
<div class="child">Centered content.</div>
</div>
</body>
</html>

本文介绍了一种使用CSS Grid实现内容居中的方法,通过定义.grid-centering类,设置display为grid,justify-content和align-items均为center,使div元素内的内容在水平和垂直方向上居中显示。
1240

被折叠的 条评论
为什么被折叠?



