简体   繁体   English

Flexbox:缺少一个元素

[英]Flexbox: one element is missing

I have three elements in a row. 我连续有三个元素。 I need to divide them in the following way: 我需要按以下方式划分它们:

flex: 0 0 20%;
max-width: 20%;
min-width: 20%;

But the result looks like this: 但是结果看起来像这样: 在此处输入图片说明

What exactly I want to get is that the green bar contains the sixth element. 我确切想要得到的是绿色条包含第六个元素。 How to achieve that? 如何实现呢?

You set the width to 20% that means you can have exactly 5 elements in a row. 将宽度设置为20%,这意味着您可以连续精确地包含5个元素。 If you want the next item to wrap on a new row you need to add flex-wrap: wrap 如果要让下一项包装在新行上,则需要添加flex-wrap: wrap

If you want the elements to always span 100% regardless of how many there are then simply don't specify any widht. 如果您希望元素始终跨越100%,而无论有多少元素,则只需不指定任何宽度。

 .flex { display: flex; background: blue; } .flex--element { background: green; flex-grow: 1; } 
 <div class="flex"> <div class="flex--element"> Element </div> <div class="flex--element"> Element </div> <div class="flex--element"> Element </div> <div class="flex--element"> Element </div> </div> 

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

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