html - 是否可以用 CSS 实现这种网格布局

标签 html css

我想实现类似这样的布局

enter image description here

问题是我只需要为盒子使用一个 UL 并使其水平放置。所以这就是我所做的: 我创建了 UL ,其中的列表项相互 float ,但没有实现这一点 - 这是发生了什么:

enter image description here

我不明白为什么列表项的第二行会变成那样而不是嵌套在第一行中?

最佳答案

查看 Demo Here

你可以通过column-count和column-gap来完成

HTML

<ul>
    <li>
        <img src="http://placehold.it/200x300/" />
    </li>
    <li>
        <img src="http://placehold.it/200x400/" />
    </li>
    <li>
        <img src="http://placehold.it/200x500/" />
    </li>
    <li>
        <img src="http://placehold.it/200x500/" />
    </li>
    <li>
        <img src="http://placehold.it/200x400/" />
    </li>
    <li>
        <img src="http://placehold.it/200x200/" />
    </li>
</ul>

CSS

ul {
    list-style: none;
    margin: 0;
    -moz-column-count: 3;
    -moz-column-gap: 0px;
    -webkit-column-count: 3;
    -webkit-column-gap: 0px;
    column-count: 3;
    column-gap: 0px;
    width: 660px;
    margin: 10px;
}
li {
    width: 200px;
}

关于html - 是否可以用 CSS 实现这种网格布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19343626/

相关文章:

javascript - 多个音频播放器的多个音量 slider

css - 列表中绝对定位元素旁边的 float 对齐问题

html - Chrome 中的 ol 标签

javascript - 地理位置邮政编码

javascript - 如何将下拉列表复制或插入到 html 表格列

Chrome 中的 Javascript 链接错误在所有其他浏览器中工作正常?

jquery - 如何将列表中的事件元素滚动到 View 中?

html - Div与日期选择器重叠

html - 选择标签手机屏幕

html - 为什么我的带有淡入淡出效果的 Bootstrap 全屏背景轮播没有在移动设备中显示?