我已经编写了两个代码片段,使用一个css网格来居中对齐内框,但不能理解其中的区别.
我知道我们还有其他方法,但我很好奇这两种方法之间的确切区别.
哪一个更合适/正确?为什么?
First个
justify-content: center;
align-content: center;
Second个
justify-items: center;
align-items: center;
超文本标记语言
<div class="box1">
<div>Box1</div>
</div>
<div class="box2">
<div>Box2</div>
</div>
CSS
.box1, .box2 {
border: 5px solid lightgreen;
height: 250px;
width: 250px;
display: grid;
justify-content: center;
align-content: center;
margin: 5px;
}
.box2 {
display: grid;
justify-items: center;
align-items: center;
}
.box1>div, .box2>div {
background: lightgreen;
padding: 20px;
}