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

标签 html css flexbox

我有一个 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/

相关文章:

html - anchor 标记作为没有 href 的按钮

php - 我可以从 HTML 页面引用 PHP 文件中的 DIV id 或类吗?

css - 垂直对齐包含页眉和页脚的 flexbox 子项中的内容

twitter-bootstrap - 在 .d-flex 容器 Bootstrap 中使用 .col-* 4

javascript - 意外 token 错误行 41 -"y:Math.round(Math.random()*(h-cw)/cw);"

javascript - 如何添加到Android移动设备的 'Add to homescreen'弹出窗口

html - 将列表的元素与容器元素的底部对齐

html - 在 CSS 中获取总宽度(忽略溢出)

jquery 一次改变一个元素的背景

html - 当我添加位置 : absolute to my navbar, 时,justify-content: space-between 停止工作