CSS保持所有flexbox子元素的大小相同 [英] CSS Keep all flexbox children elements the same size

查看:1514
本文介绍了CSS保持所有flexbox子元素的大小相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的sass(使用指南针获取前缀)是)



如果您设置 flex- grow 为0,你告诉项目保持它们的宽度和展开空的空间。使用 flex-grow:1 这些项目会展开宽度以适应空格。



小提琴



在正常之后添加一些隐形项具有相同弹性属性的项目。



在此解决方案中,在所有可见行中将有相同数量的项目,因此请确保添加足够的隐藏项目以正常工作较大的屏幕。


My sass (using compass to get the prefixes) is shown in this fiddle :

.container
   @include display-flex
   @include flex-wrap(wrap)
   .item
       @include flex-grow(1)
       @include flex-basis(190px)

Although, I would like the two items across the bottom to have the same with as the items on the top.

I don't want to float them left and fix their width, this will not work for my arrangement in other resolutions.

Any suggestions welcome!

解决方案

You have 2 ways of doing this:

flex-grow: 0 (fiddle)

If you set flex-grow to 0 you are telling the items to keep their width and expand the empty space. Using flex-grow: 1 the items will expand the width to fit the space.

invisible items (fiddle)

Add some invisible items after the normal items with the same flex properties. You will get a left aligned look.

In this solution there will be the same number of items in all visible rows so make sure to add enough invisible items to work properly on larger screens.

这篇关于CSS保持所有flexbox子元素的大小相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆