gpt4 book ai didi

html - CSS flex-item align self 不适用于 flex-wrap parent

转载 作者:太空宇宙 更新时间:2023-11-03 21:06:30 30 4
gpt4 key购买 nike

我有一个 flex 父容器设置为 flex-wrap: wrapjustify-content: flex-end。我有一个 flex-child,button-group,我想将其与 flex-start 对齐,但是 align-self 不起作用。

.container{
width: 500px;
height: 500px;
background: pink;

display: flex;
justify-content: flex-end;
flex-wrap: wrap;
}

.button-group {
background: lightblue;
align-self: flex-start; /* Not working!*/
padding: 5px 10px;
}

.main-box {
width: 450px;
height: 300px;
background: lime;
}

.myfooter {
width: 50%;
height: 10%;
background-color: black;
}
<div class="container">
<div class="button-group">
<button></button>
<button></button>
<button></button>
</div>

<div class="main-box"></div>
<div class="myfooter"> </div>
</div>

如何让按钮组向左对齐,同时保留 flex wrap?

最佳答案

Flexbox 在一维方向对齐元素。这就是 flex-start 不起作用的原因,

为了让它工作,用 div 包装它并添加适当的样式,如代码片段所示

.container {
width: 500px;
height: 500px;
background: pink;
display: flex;
justify-content: flex-end;
flex-wrap: wrap;
}

.button-group {
background: lightblue;
padding: 5px 10px;
display: inline-block;
}

.main-box {
width: 450px;
height: 300px;
background: lime;
}

.myfooter {
width: 50%;
height: 10%;
background-color: black;
}
.holder{width: 100%;}
<div class="container">
<div class="holder">
<div class="button-group">
<button>1</button>
<button>2</button>
<button>3</button>
</div>
</div>

<div class="main-box"></div>
<div class="myfooter"> </div>
</div>

关于html - CSS flex-item align self 不适用于 flex-wrap parent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52034461/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com