想知道是否可以获得与pinterest或jQuery砖石相同类型的设计布局,只使用新的flexBox布局.这就是我所得到的:
.flex-container { display: -webkit-flex; display: flex; -webkit-flex-flow: row wrap; flex-flow: row wrap; } .item { width: 220px; height: 250px; margin: 10px auto; padding: 0; background: #ccc; } .item:nth-child(3n+2) { background: #aaa; height: 400px; }
和HTML我只是使用一个PHP循环来创建12个项目
<?PHP for ($i=0; $i<=11; $i++) { echo '<div class="item"></div>'; } ?>
这是完全可能的.
原文链接:https://www.f2er.com/php/132181.html感谢@ leopld的原始答案,我能够创建一个不依赖于一个固定高度的.
通过使flex容器的位置:absolute或position:fixed,可以让它动态地填充可用空间.
链接到Codepen:http://codepen.io/anon/pen/Jpnyj?editors=110.我包括了您现在需要的所有供应商前缀.
<div class="wrapper"> <div class="Box Box-red"></div> <div class="Box Box-blue"></div> <div class="Box Box-pink"></div> <div class="Box Box-purple"></div> <div class="Box Box-green"></div> <div class="Box Box-yellow"></div> <div class="Box Box-brown"></div> <div class="Box Box-red"></div> <div class="Box Box-blue"></div> <div class="Box Box-pink"></div> <div class="Box Box-purple"></div> <div class="Box Box-green"></div> <div class="Box Box-purple"></div> <div class="Box Box-green"></div> <div class="Box Box-yellow"></div> <div class="Box Box-blue"></div> <div class="Box Box-pink"></div> <div class="Box Box-purple"></div> <div class="Box Box-green"></div> <div class="Box Box-yellow"></div> <div class="Box Box-red"></div> <div class="Box Box-brown"></div> <div class="Box Box-blue"></div> <div class="Box Box-red"></div> <div class="Box Box-green"></div> <div class="Box Box-yellow"></div> <div class="Box Box-brown"></div> </div>
样式
body { background: black; } .wrapper { position: absolute; width: 100%; height: 100%; display: -webkit-Box; display: -webkit-flex; display: -ms-flexBox; display: flex; -webkit-flex-flow: column wrap; -ms-flex-flow: column wrap; flex-flow: column wrap; -webkit-Box-align: stretch; -webkit-align-items: stretch; -ms-flex-align: stretch; align-items: stretch; -webkit-align-content: stretch; -ms-flex-line-pack: stretch; align-content: stretch; } .Box { margin: 5px; -webkit-Box-flex: 0; -webkit-flex: 0 1 auto; -ms-flex: 0 1 auto; flex: 0 1 auto; } .Box-red { height: 100px; background: red; } .Box-blue { height: 120px; background: blue; } .Box-pink { height: 144px; background: pink; } .Box-purple { height: 250px; background: purple; } .Box-green { height: 200px; background: green; } .Box-yellow { height: 20px; background: yellow; } .Box-brown { height: 290px; background: brown; }