简体   繁体   English

具有最大高度的 flex 元素的列对齐

[英]column aligment for flex element with max-height

here is flex element with flex: column wrap;这是带有flex: column wrap; flex 元素flex: column wrap; and max-height: 150px;max-height: 150px; . . My problem is that justify-content not working.我的问题是justify-content不起作用。 But working with height: 150px .但是使用height: 150px For container with max-width: 100%;对于max-width: 100%;容器max-width: 100%; & flex-direction: row; & flex-direction: row; aligment works properly对齐工作正常

 .container { max-height: 150px; display: flex; flex-flow: column wrap; justify-content: center; } .item { width: 25%; height: 50px; border: 1px solid #000; box-sizing: border-box; }
 <div class="container"> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> </div>

Result结果

Expected result预期结果

Not sure if it's a bug or an intended result but you can fix it if you consider an extra wrapper where you apply the max-height property:不确定这是错误还是预期结果,但如果您考虑使用额外的包装器来应用max-height属性,则可以修复它:

 .container { display: flex; flex-flow: column wrap; justify-content: center; width:100%; } .item { width: 25%; height: 50px; border: 1px solid #000; box-sizing: border-box; } .extra { max-height: 150px; display:flex; }
 <div class="extra"> <div class="container"> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> </div> </div>

Worth to note that if you consider height instead of max-height it works fine:值得注意的是,如果您考虑height而不是max-height它工作正常:

 .container { display: flex; flex-flow: column wrap; justify-content: center; height: 150px; } .item { width: 25%; height: 50px; border: 1px solid #000; box-sizing: border-box; }
 <div class="container"> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM