Skip to main content

水平垂直居中

使用 grid,它是做二维布局的,但是只有一个子元素时,一维布局与二维布局就一样了。结合 justify-content/justify-items 和 align-content/align-items 就有四种方案

.container {
display: grid;
justify-content: center;
align-content: center;
}
.container {
display: grid;
justify-content: center;
align-items: center;
}
.container {
display: grid;
justify-items: center;
align-content: center;
}
.container {
display: grid;
justify-items: center;
align-items: center;
}