【发布时间】:2017-03-09 22:38:29
【问题描述】:
我正在尝试垂直对齐白框,使它们位于图片的中间。我尝试使用 align-items: center;但是我需要为我不想的行类添加高度。
http://codepen.io/VK72m/pen/ZeLaNx
<div class="container">
<div class="row">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
<div class="row">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
body {
margin: 0;
padding: 0;
font-size: 100%;
}
.container {
align-items: center;
margin: 0;
padding: 0;
height: 19em;
width: 20em;
background-color: black;
background: url("https://images.pexels.com/photos/340779
/pexels-photo- 340779.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb");
background-position: -22em ;
}
.row {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
.box {
margin: 0;
padding: 0;
height: 3em;
width: 3em;
margin: 0.9em;
background-color: white;
}
【问题讨论】: