CSS flex 盒 : filling blank space between vertical elements

标签 css flexbox

我对 flexbox 有疑问: 我有 HTML:

<div class="panel-body">
   <div class="project">

   </div>

   <div class="project">

   </div>
   <div class="project">

   </div>
   <div class="project">

   </div>
   <div class="project">

   </div>
 </div>

你可能明白了......

现在,我希望它看起来像这样:

|元素| |元素| |元素|

|元素| |元素| |元素|

|元素| |元素| |元素|

等..

但是,有些元素比其他元素高。所以大约一年前,我设法用 isotope.js 插件很好地放置它们,就像这样:

Isotope can do that pretty simply

如您所见,“5555”项紧跟在“Nexus 5”之后,“44444”和“Nexus 7”也是如此。

问题是,我如何使用 flexbox 做到这一点?这可能吗?

我当前的 CSS 代码:

.panel-body{
   display: flex;
   flex-wrap: wrap;
   align-items: flex-start;
}

.panel-body .project {
   flex-grow: 1;
   flex-shrink: 1;
   flex-basis: 300px;
   margin: 1px 10px;
}

这就是它现在的样子(箭头告诉你我想要它的样子)

Flexbox Problem

最佳答案

你还不能用 flex-box 做到这一点。但是,CSS3 columns 可能会为您提供接近您所追求的东西。

演示:http://jsfiddle.net/abhitalks/nHbdL/

HTML 标记:

与您的问题相同。

CSS:

div.panel-body { 
    height: 600px;        /* fixed height allows you to control column fill */
    -webkit-columns: 3;   /* number of columns that you want */
    column-count: 3;      /* the standard property after all prefixed ones */
}

div.project {
    background-color: #cfffbd;
    -webkit-column-break-inside: avoid; /* will prevent breaking blocks across columns */
    column-break-inside: avoid;         /* the standard property after all prefixed ones */
}

.

关于CSS flex 盒 : filling blank space between vertical elements,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24453263/

相关文章:

html - IE11 : Position absoluted DIV inside Flex container keeps out of the flow

css - 在这个 flexbox 布局中,这个 CSS 计算来自哪里?

html - 具有剩余宽度、省略号和新行上的一些内容的 Flexbox 列表

html - 将图像包裹在 div 中

CSS3 Scale 不适用于 Firefox 34.0.5 中的 <a>

jquery - 如何在悬停在 div 上时显示叠加文本并在 html 和 css 中隐藏 div 上的当前文本

html - 页脚始终位于底部,带有 "flexbox"(IE 11 上的问题)

css - 优先考虑 flexbox 中的盒子

JavaScript 拖放在 Chrome 中有效,但在 IE 中无效

css - 使用 JS 或 SVG 和 css 动画圆形 Logo