Home >Web Front-end >CSS Tutorial >How to implement waterfall flow layout using JS or CSS, several solutions are introduced
This article will take you through the waterfall flow layout and introduce three reliable JS solutions and N unreliable CSS solutions. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
In the spirit of practicality, we will share today Waterfall flow layout (Yesterday a little brother asked me how to do it, I looked I couldn't find it after a long time. It turns out it was written on the intranet ).
Demo address: http://www.lilnong.top/static/html/waterfall.html
For example, huapetal.com and Mogujie (I posted pictures below), these websites use waterfall flow layout when displaying content.
We also want to make a page that displays our design draft (fixed width, variable height). Waterfall flow is a great solution.
The core of the waterfall flow layout is based on a grid layout, and the height of the item list contained in each row is random (the height changes dynamically with its own content), and each item The list is arranged in a stack, and the most important thing is that there is no unnecessary space between the stacks. Let’s take a look at the picture above to see what the waterfall flow layout we are talking about looks like.
Website | Mogujie | 花pet网 | JD | VV |
---|---|---|---|---|
screenshot | ||||
Scheme | Sub-channel | absolute |
Depend on document flow, from left to right, top to bottom.
grid | inline | float | bootstrap-grid | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
columns | flex | |
---|---|---|
.
The default is horizontal arrangement, and it can be modified to vertical arrangement and Allows wrapping, and then wraps the content with a fixed height. Absolute, channel height calculation scheme
Get the remainder channel | Calculate the height channel | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
方案 | 优点 | 缺点 | 点评 |
---|---|---|---|
columns | 实现简单、纯 CSS 方案 | 兼容性 | - |
flex | - | 需要固定高度,填充难以控制等问题 | - |
float、inline、bootstrapGrid | - | - | 没点大都用不出这方案 |
grid | - | - | 可以nth-child模拟实现、或者等待兼容性 masonry |
absolute | 效果好 | - | JS计算无限可能 |
js普通通道 | - | 填充难以控制 | - |
js优化通道 | 效果好、无绝对定位 | 在出现夸列等操作的时候不是很好控制 | - |
更多编程相关知识,请访问:编程入门!!
The above is the detailed content of How to implement waterfall flow layout using JS or CSS, several solutions are introduced. For more information, please follow other related articles on the PHP Chinese website!