html - css列响应式设计

标签 html css responsive-design

我有 div 元素,所有元素都具有指定的未知高度。 现在我想通过将它们放在 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


我试过:

.entry { display: inline-block }

问题:由于高度不一样,未使用的空间太多

.entry { float: left }

问题:与 display:inline-block 相同的问题

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

问题排序不是从左到右而是从上到下


如何按水平顺序从左到右对它们进行排序?


1 行:

1
2
3
.
.

2 行:

1 2
3 4
5 6
.
.

3 行:

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

4 行:

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

最佳答案

在没有任何标记的情况下很难精确定位,但是您可以尝试使用 Flexbox 吗? Flexbox 将确保它们保持相同的高度,并正确流动。大致如下:

.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);
    }
}

您需要使用带前缀的版本(或 Autoprefixer)和正确的媒体查询。

关于html - css列响应式设计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30005168/

相关文章:

html - 为什么 jQuery UI Spinner 箭头按钮不显示?

html - 复选框在单独的行上内联渲染

css - 响应式电子邮件模板 android 2.3.6

javascript - UIB 选项卡集不起作用

html - 如何在带有 id 修饰符的 ul 中选择一个 li?

jQuery:如何避免对 mask div 产生透明效果

css - Bootstrap 响应 - 在移动设备上查看时忽略 'spanX'

javascript - IE11 中的 jQuery - $(document).width() 和 $ ("html").width() 之间的差异

html - 将 Logo 图像居中并将响应式导航栏放在 Logo 正下方

html - 如何将 div 内容放入移动 View 的下拉列表中