html - 以水平顺序而不是垂直顺序显示 css 列

标签 html css

<分区>

我有这个代码:

<div id="columns">
    <div id="box1">box1</div>
    <div id="box2">box2</div>
    <div id="box3">box3</div>
    <div id="box4">box4</div>
    <div id="box5">box5</div>
    <div id="box6">box6</div>
</div>

CSS:

.column {
column-count: 3;
column-gap: 0px;
column-fill: auto;
margin: auto;
}   

#box(n) {
display: inline-block;
padding: 0 10px;
margin: 10px 10px;
}

我得到:

盒子1 盒子4
box2 box5
box3 box6

我想要的:

盒子1盒子2
box3 box4
box5 box6

任何人都可以帮助我如何使用纯 html/css 来实现吗?我正在尝试使用 pinterest 风格(不同高度的盒子)。

enter image description here

最佳答案

尝试使用 float :

演示:http://jsfiddle.net/GCu2D/912/

HTML

<div id="columns">
    <div id="box1">box1</div>
    <div id="box2">box2</div>
    <div id="box3">box3</div>
    <div id="box4">box4</div>
    <div id="box5">box5</div>
    <div id="box6">box6</div>
</div>

CSS:

#columns {
    width:400px; /* change it according to your design*/
}
#columns div {
    float:left;
    width:50%;/*so as to give equal width to div */
    outline:1px solid red;/*optional*/
    height:400px;/*use your own value*/
}
#columns:after {
    content:"";
    display:block;
    clear:both;
}

关于html - 以水平顺序而不是垂直顺序显示 css 列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33208112/

相关文章:

javascript - onClientClick for asp :element within a listview

html - 如何在thead中安排内容

javascript - 初学者的 html div 覆盖

javascript - 如何设置css属性为伪类原生js

html - 无法使Footer的文本对齐或margin:auto居中。小文字也不起作用

jquery - 创建具有滑动页面效果的单页站点

php - 按日期选择器范围对表进行排序

html - 使用 Bootstraps 网格时更改主体的背景颜色

css - 响应式网站在移动浏览器中看起来不同

jquery - 像素密度会影响元素在各种设备上的定位吗?