flex实现瀑布流布局

本文详细介绍了如何利用Flexbox布局实现动态瀑布流效果,包括元素的排列、间距调整和响应式设计,适用于网页和移动端展示项目。
摘要由CSDN通过智能技术生成
<!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";
  
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值