我有一个flexbox div container
与align-items: center
,有三个孩子。其中之一有max-width: 200px
(在代码中,second-ch
),它也是一个灵活的两个孩子分配justify-content: space-between
,但second-ch
未遵循其max-width
。如果我从container
中删除align-items: center
,second-ch
再次取得所需的宽度,但其余元素不再位于中心。我该如何解决这个问题?Flexbox“align-items:center”缩小了孩子的最大宽度
.container {
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
}
.first-ch {
width: 70px;
height: 70px;
background-color: grey;
}
.second-ch {
max-width: 200px;
height: 80px;
background-color: red;
display: flex;
justify-content: space-between;
}
.square {
width: 50px;
height: 50px;
background-color: yellow;
margin: 5px;
}
.third-ch {
width: 50px;
height: 50px;
background-color: blue;
}
<div class="container">
<div class="first-ch"></div>
<div class="second-ch">
<div class="square"></div>
<div class="square"></div>
</div>
<div class="third-ch"></div>
</div>
这是你想要的吗? https://jsfiddle.net/mmroz5ks/ – ketan