简体   繁体   English

CSS列响应式设计

[英]css columns responsive design

I have div elements with all with specified unknowen heights. 我有所有具有指定未知高度的div元素。 Now I want to create an responsive design by putting them in 1<=n<=4 rows. 现在,我想通过将它们放入1 <= n <= 4行来创建响应式设计。

<div id="timeline">
     <div class="entry" style="height: (any height e.g. 222px)">
         <div class="background"></div>
         <div class="image"></div>
         <div class="entrytext">sometext</div>
     </div>
     <div class="entry" style="height: (any height e.g. 174px)">
         <div class="background"></div>
         <div class="image"></div>
         <div class="entrytext">sometext</div>
     </div>
     .
     .
     .
</div>

jsFiddle here jsFiddle在这里


I tried: 我试过了:

.entry { display: inline-block }

problem: too much unused space because of the heights that not the same 问题:由于高度不同,未使用的空间过多

.entry { float: left }

problem: same problem as by display:inline-block 问题:与display:inline-block相同的问题

#timeline { column-count: n (e.g 3) }

problem sorting from top to bottom not from left to right 从上到下而不是从左到右排序的问题


How can I sort them from left to right in a horizantal order? 如何按水平顺序从左到右对它们进行排序?


1 row: 1行:

1
2
3
.
.

2 rows: 2行:

1 2
3 4
5 6
.
.

3 rows: 3行:

1 2 3
4 5 6
7 8 9
.
.
.

4 rows: 4行:

01 02 03 04
05 06 07 08
09 10 11 12
.
.

It's a little hard to pinpoint without any markup, but can you try using Flexbox? 没有任何标记很难确定,但是您可以尝试使用Flexbox吗? Flexbox will ensure they maintain the same height, and flow correctly. Flexbox将确保它们保持相同的高度并正确流动。 Something along the lines of the following: 遵循以下内容:

.container { // #timeline in your case yes?
    display: flex;
    flex-wrap: wrap;
}

.entry {
    width: 100%; // Shouldn't actually need this declaration

    @from 2 { // Replace with your breakpoint
        width: calc(100% / 2);
    }

    @from 3 { // Replace with your breakpoint
        width: calc(100% / 3);
    }

    @from 4 { // Replace with your breakpoint
        width: calc(100% / 4);
    }
}

You'll need to use prefixed versions (or Autoprefixer), and the correct media queries. 您需要使用带前缀的版本(或自动前缀),以及正确的媒体查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM