【发布时间】:2014-10-14 18:32:34
【问题描述】:
假设我们有一个容器,它的子元素必须在列中填充它。容器的高度是有限的,并且必须与所有后代的需要一样宽/窄才能适合。它应该是这样的:
为了做到这一点,我尝试flexbox。问题是:是否有可能使其缩小以适应?
-
float:left:在 Chrome 中根本无法解决问题,在 Firefox 中,容器只有一列的宽度 - example 1 -
position:absolute:对正常流量没有贡献,所以丢弃它。
现在我将浏览器范围缩小到 Chrome 和 FF。
HTML:
<div class="flexcontainer wrap column">
<div></div>
<div></div>
...
</div>
CSS:
.flexcontainer{
display: flex; /* make it a flexbox */
flex-flow: column wrap; /* make it a column container, and fill them one after another */
align-content: stretch;
align-items: center;
justify-content: center;
float: left; /* shrink-to-fit */
max-height: 450px; /* limit the height */
min-height: 300px;
}
.flexcontainer > div {
height: 100px;
margin: 3px;
width: 100px; /* set the width of descendants */
}
谢谢!
【问题讨论】:
-
是否有最大项目数?
-
另外,您的页面是否可以超出视口的正常宽度和高度?
-
关于你如何解决这个问题的任何更新,或者 jquery 是唯一的方法吗?