


In the previous article "How to add dynamic color-changing effects to background images in CSS3", we introduced the method of creating color-changing background image animations to make web pages look high-end! This time we will talk about how to use the CSS3 column series properties to implement waterfall flow layout. Friends who are interested can learn more~
When we mention CSS responsive layout, we will want to use Grid and Flexbox to implement it. , in fact they also have some limitations. Things like waterfall flow layout cannot be easily implemented using them.
The reason for this is that waterfall flows generally have the same width, but the height is adaptive according to the picture. And the position of the picture is also based on the position of the picture above.
So how to use pure CSS3 to implement waterfall flow layout? We can take advantage of the CSS3 column series properties!
Let’s start with the code directly:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style> body, html { position: relative; width: 100%; height: 100%; background: #4f000b; font-family: "PT Mono", monospace; } .masonry { -moz-column-count: 1; column-count: 1; /* 设置列数 */ -moz-column-gap: 0; column-gap: 0; /* 设置列间距 */ counter-reset: item-counter; } /* 根据不同的屏幕宽度 设置不同的列数*/ @media screen and (min-width: 400px) { .masonry { -moz-column-count: 2; column-count: 2; } } @media screen and (min-width: 600px) { .masonry { -moz-column-count: 3; column-count: 3; } } @media screen and (min-width: 800px) { .masonry { -moz-column-count: 4; column-count: 4; } } @media screen and (min-width: 1100px) { .masonry { -moz-column-count: 5; column-count: 5; } } .item { box-sizing: border-box; -moz-column-break-inside: avoid; break-inside: avoid; padding: 10px; counter-increment: item-counter; } .item__content { position: relative; display: flex; flex-direction: column; justify-content: center; align-items: center; height: 220px; font-size: 40px; color: #360007; background: currentColor; box-sizing: border-box; color: #720026; } .item__content:hover { background: #9b0034; } .item__content:before { position: absolute; top: 0; left: 0; font-size: 13px; width: 2em; height: 2em; line-height: 2em; text-align: center; font-weight: bold; background-color: #222; content: counter(item-counter); } .item__content--small { color: #ce4257; height: 100px; } .item__content--small:hover { background: #d66274; } .item__content--medium { color: #ffc093; height: 175px; } .item__content--medium:hover { background: #ffd8bc; } .item__content--large { color: #ff7f51; height: 280px; } .item__content--large:hover { background: #ff9d7a; } </style> </head> <body> <div class="masonry"> <div class="item"> <div class="item__content"> </div> </div> <div class="item"> <div class="item__content item__content--small"> </div> </div> <div class="item"> <div class="item__content item__content--medium"> </div> </div> <div class="item"> <div class="item__content item__content--small"> </div> </div> <div class="item"> <div class="item__content item__content--medium"> </div> </div> <div class="item"> <div class="item__content"> </div> </div> <div class="item"> <div class="item__content item__content--large"> </div> </div> <div class="item"> <div class="item__content item__content--medium"> </div> </div> <div class="item"> <div class="item__content item__content--small"> </div> </div> <div class="item"> <div class="item__content"> </div> </div> <div class="item"> <div class="item__content item__content--large"> </div> </div> <div class="item"> <div class="item__content"> </div> </div> <div class="item"> <div class="item__content item__content--small"> </div> </div> <div class="item"> <div class="item__content item__content--large"> </div> </div> <div class="item"> <div class="item__content item__content--medium"> </div> </div> <div class="item"> <div class="item__content item__content--small"> </div> </div> <div class="item"> <div class="item__content item__content--medium"> </div> </div> <div class="item"> <div class="item__content"> </div> </div> <div class="item"> <div class="item__content item__content--small"> </div> </div> </div> </body> </html>
The effect is as shown below:
ok, The waterfall flow layout is implemented! So let’s analyze the above code and introduce you to several key css attributes:
@media
Query: Different styles can be set for different screen sizes
@media mediatype and|not|only (media feature) { CSS-Code; }
column-count
Attribute: Specifies the number of columns an element should be divided into.column-gap
Property: Specifies the column gap.
column-gap: length|normal; length 一个指定的长度,将设置列之间的差距 normal 指定一个列之间的普通差距。 W3C建议1EM值
-
break-inside
Attribute: Describes how the content box under the multi-column layout page is broken if the multi-column layout has no content box, this attribute will be ignored.In the above example:
.item { break-inside: avoid; box-sizing: border-box; padding: 10px; }
break-inside:avoid
In order to control the text block to be broken into separate columns to prevent the content of the item list from spanning columns, destroying the overall layout.
counter-increment
Attribute: Increment one or more counter values, usually used for counter-reset attribute and content attribute. For example, in the above example:
.item { counter-increment: item-counter; } .item__content:before { content: counter(item-counter); }
The PHP Chinese website platform has a lot of video teaching resources. Everyone is welcome to learn "css Video Tutorial"!
The above is the detailed content of How to create waterfall layout using pure CSS3? Brief analysis of columns method. For more information, please follow other related articles on the PHP Chinese website!

两种方法:1、利用display属性,只需给元素添加“display:none;”样式即可。2、利用position和top属性设置元素绝对定位来隐藏元素,只需给元素添加“position:absolute;top:-9999px;”样式。

怎么制作文字轮播与图片轮播?大家第一想到的是不是利用js,其实利用纯CSS也能实现文字轮播与图片轮播,下面来看看实现方法,希望对大家有所帮助!

实现方法:1、使用“:active”选择器选中鼠标点击图片的状态;2、使用transform属性和scale()函数实现图片放大效果,语法“img:active {transform: scale(x轴放大倍数,y轴放大倍数);}”。

自适应布局又称“响应式布局”,是指可以自动识别屏幕宽度、并做出相应调整的网页布局;这样的网页能够兼容多个不同的终端,而不是为每个终端做一个特定的版本。自适应布局是为解决移动端浏览网页而诞生的,能够为使用不同终端的用户提供很好的用户体验。

css3中的动画效果有变形;可以利用“animation:动画属性 @keyframes ..{..{transform:变形属性}}”实现变形动画效果,animation属性用于设置动画样式,transform属性用于设置变形样式。

在css3中,可以利用“animation-timing-function”属性设置动画旋转速度,该属性用于指定动画将如何完成一个周期,设置动画的速度曲线,语法为“元素{animation-timing-function:速度属性值;}”。

css3线性渐变可以实现三角形;只需创建一个45度的线性渐变,设置渐变色为两种固定颜色,一个是三角形的颜色,另一个为透明色即可,语法“linear-gradient(45deg,颜色值,颜色值 50%,透明色 50%,透明色 100%)”。

本篇文章带大家一起深入了解一下CSS3中的新特性::target-text 选择器,聊聊该选择器的作用和使用方法,希望对大家有所帮助!


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver Mac version
Visual web development tools