<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS 实现瀑布流布局(display: flex)</title>
</head>
<style>
.g-container {
display: -webkit-box;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
flex-direction: row;
-webkit-box-pack: justify;
justify-content: space-between;
overflow: hidden;
}
.g-queue {
display: -webkit-box;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
flex-direction: column;
flex-basis: 24%;
}
.g-item {
position: relative;
width: 100%;
margin: 2.5% 0;
}
.g-queue:nth-child(1) .g-item:nth-child(1) {
height: 247px;
background: #5a78a2;
}
.g-queue:nth-child(1) .g-item:nth-child(1)::after {
content: "1";
position: absolute;
color: #fff;
font-size: 24px;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.g-queue:nth-child(1) .g-item:nth-child(2) {
height: 305px;
background: #694271;
}
.g-queue:nth-child(1) .g-item:nth-child(2)::after {
content: "2";
position: absolute;
color: #fff;
font-size: 24px;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.g-queue:nth-child(1) .g-item:nth-child(3) {
height: 180px;
background: #923289;
}
.g-queue:nth-child(1) .g-item:nth-child(3)::after {
content: "3";
position: absolute;
color: #fff;
font-size: 24px;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.g-queue:nth-child(1) .g-item:nth-child(4) {
height: 350px;
background: #e42fa4;
}
.g-queue:nth-child(1) .g-item:nth-child(4)::after {
content: "4";
position: absolute;
color: #fff;
font-size: 24px;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.g-queue:nth-child(1) .g-item:nth-child(5) {
height: 64px;
background: #e719eb;
}
.g-queue:nth-child(1) .g-item:nth-child(5)::after {
content: "5";
position: absolute;
color: #fff;
font-size: 24px;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.g-queue:nth-child(1) .g-item:nth-child(6) {
height: 160px;
background: #68e35c;
}
.g-queue:nth-child(1) .g-item:nth-child(6)::after {
content: "6";
position: absolute;
color: #fff;
font-size: 24px;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.g-queue:nth-child(1) .g-item:nth-child(7) {
height: 322px;
background: #ad1428;
}
.g-queue:nth-child(1) .g-item:nth-child(7)::after {
content: "7";
flex实现瀑布流布局
最新推荐文章于 2024-08-02 16:18:47 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)