css - 多个高度框都在顶部

标签 css grid flexbox

我知道这对于 css 2 是不可能的,但是现在有了 Flexbox...

图片上的这个技巧只用CSS就可以实现吗?

http://img11.hostingpics.net/pics/430383flexbox.jpg http://img11.hostingpics.net/pics/430383flexbox.jpg

HTML:

<div></div>
<div></div>
<div></div>
<div></div>
<div></div>

最佳答案

恐怕开发人员想要实现的目标仍然不可能实现。

砖石布局,带有“ float ”框但从左到右阅读是不可能的,即使使用 flexbox

演示:http://jsfiddle.net/g8Ky9/

在示例中,您可以看到您拥有的备选方案;第三个看起来很有希望,但盒子顺序可能不是你想要的(从上到下而不是从左到右)

确定您可以使用 css-flexbox 的属性 order 轻松切换框,但您需要 javascript 来实现它,并且计算正确的偏移量并不容易

承认这真的很遗憾,但即使使用 CSS3 也无法实现这个目标

.container
    {padding:10px;border:1px red solid;width:960px;display:flex;flex-wrap:wrap;flex-direction:row;align-items:flex-start;}

.container > div
    {padding:10px;width:200px;margin:10px;background:red;font-size:20px;text-align:center;font-weight:bold;font-family:sans-serif;}

.container.t1
    {align-items:stretch;}

.container.t2
    {flex-direction:column;height:180px;}

.container > div:nth-child(1){min-height:20px}
.container > div:nth-child(2){min-height:40px}
.container > div:nth-child(3){min-height:60px}
.container > div:nth-child(4){min-height:40px}
.container > div:nth-child(5){min-height:20px}
.container > div:nth-child(6){min-height:60px}
.container > div:nth-child(7){min-height:40px}
.container > div:nth-child(8){min-height:20px}


that's the base:
<div class="container">
    <div>1</div><div>2</div><div>3</div><div>4</div>
    <div>5</div><div>6</div><div>7</div><div>8</div>
</div>

you can fill the empty space:
<div class="container t1">
    <div>1</div><div>2</div><div>3</div><div>4</div>
    <div>5</div><div>6</div><div>7</div><div>8</div>
</div>

or do the masonry layout like this, but with order of boxes wrong:
<div class="container t2">
    <div>1</div><div>2</div><div>3</div><div>4</div>
    <div>5</div><div>6</div><div>7</div><div>8</div>
</div>

关于css - 多个高度框都在顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20787553/

相关文章:

html - 我想在侧边栏 div 下显示列表

wpf - 创建一个方形用户控件

CSS:使图像下方带有文本响应

css - IE 10/11 flex 子溢出对齐的解决方法

php - 使用 php、js 和 mysql 的导航菜单

用于可点击菜单和水平导航的 Javascript 或 css

javascript - 在元素类更改时运行 jQuery 回调?

javascript - Web按钮只能使用一次,然后我必须刷新页面

css - 图像的网格问题

html - 在 flexbox li 元素中底部对齐图像