html - CSS flex-item align self 不适用于 flex-wrap 父级
问题描述
我有一个 flex 父容器设置为flex-wrap: wrap
and justify-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>
如何让按钮组在保留弹性包装的同时向左对齐?
解决方案
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>
推荐阅读
- php - 尝试执行包含 PHP 包含的 PHP 文件 - 从命令行
- javascript - 向下滚动时的 JavaScript 文本动画
- java - API 在 IntelliJ 中有效,但在 Android Studio 中无效
- typescript - 从@types/chrome 导入接口不起作用
- java - 如何为日志文件和控制台获取不同的日志级别?
- javascript - 如何使用 javascript 或 php 在外部浏览器而不是应用程序中打开链接(在 youtube 视频中提供)
- algorithm - 根据开始和结束时间对赛车手进行排名
- c# - VISUAL STUDIO .NET MVC 无法搭建剃刀视图
- sql - 按部门id排序,列出经理姓名,管理整个部门的经理的部门名称
- flutter - 如何使颤动的视频播放器响应?