像我之前的许多人一样,我想将弹性盒中的最后一个孩子移到弹性盒末端。
我已经找到了我问题的答案。解决方案使用margin: auto
:
.container {
width: 100%;
display: flex;
justify-content: flex-start;
}
.last-child {
// justify-self: flex-end; why does this not work?
margin-left: auto;
}
但是我想知道为什么justify-self
不能那样工作?Margin: auto
对我来说感觉就像是骇客。有没有解决此问题的灵活方法?不justify-self
喜欢不工作justify-content
,而是justify-item
在一个容器级别?
谢谢您的支持!
justify-self
flexbox中没有用于flex-items
将它们在主轴上对齐的属性。对于横轴,align-self
虽然有flex-items
垂直对齐的属性。
如果您不喜欢在主轴margin
上对齐flex-items
,则还可以span
在最后一个子项之前添加一个空标记,并为其指定flex-grow: 1
CSS以获得相同的结果。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句