所以我在谷歌上搜索了很多,没有找到解决这个问题的方法。我想要两个项目是水平和垂直居中。这里的诀窍是,我想将它们堆叠在一起,位置:绝对没有问题,但我不能将元素放在绝对位置的中心。我认为这应该适用于flexbox。对于堆叠,我的意思是一个元素部分隐藏了另一个元素。

发布于 2015-07-22 17:51:08
容器可以设置水平居中和垂直居中的align-items: center和justify-content: center。
.outer {
align-items: center;
background: #800000 none repeat scroll 0 0;
border: 5px solid #353535;
border-radius: 50%;
display: flex;
height: 300px;
justify-content: center;
position: relative;
width: 300px;
}
.inner {
background: #C83737;
border: 5px solid #353535;
width: 150px;
height: 150px;
border-radius: 50%;
}<div class="outer">
<div class="inner"></div>
</div>
发布于 2015-07-22 17:57:08
也许是这样的?fiddle
<div class="container">
<div class="item"></div>
<div class="item"></div>
</div>
.container {
display: flex;
flex-flow: wrap;
align-items: center;
justify-content: center;
border: 1px solid black;
height: 500px;
width: 100%;
align-content: center;
}
.item {
flex: 1 100%;
border: 1px solid black;
height: 100px;
}发布于 2015-07-22 18:04:25
<div class='item1'>
<div class='item2'></div>
</div>
html, body{
height: 100%;
}
body{
display: flex;
flex:1 1 auto;
justify-content:center;
align-items:center
}
.item1 {
display: flex;
width: 200px;
height: 200px;
background: red;
justify-content: space-around;
align-items:center
}
.item2 {
width: 100px;
height: 100px;
background: green;
}https://stackoverflow.com/questions/31559523
复制相似问题