【发布时间】:2022-01-19 20:55:15
【问题描述】:
我在父容器中嵌套了 3 个按钮。父容器有display:inline-flex,但justify-content: space-between 属性不起作用。这些按钮定义了max-width(因为justify-content 只能在有可用空间时工作)。此时,当我为justify-content(space-between、space-around、center 等)尝试不同的值时,按钮的分组会四处移动,但各个按钮永远不会分开。我已经对此进行了一段时间的修改,并阅读了一堆 StackOverflow 答案,但到目前为止没有任何效果。任何帮助表示赞赏! I have a codepen for testing things out. 这是我的 Angular 代码的简化版本。
为了完整记录我的问题,这里是生产中的相关代码和屏幕截图:
.loop-container {
display: inline-flex
flex-direction: row
justify-content: space-between
align-items: center
}
button {
height: 30px
flex: 1
}
.cancel {
background-color: red
}
.home {
background-color: blue
}
.small {
max-width: 75px
}
.large {
max-width: 140px
}
<ng-container class="button-container">
<div class='loop-container'>
<button class='cancel small'>Cancel</button>
<button class='home small'>Home</button>
<button class='cancel large'>Cancel Machine</button>
</div>
</ng-container>
【问题讨论】:
-
flex: 1在按钮上应用flex-grow: 1,告诉每个项目消耗所有可用空间。因此,父级上的justify-content属性将不起作用,因为没有可用空间。
标签: html css angular sass flexbox