当前位置: 首页 > article >正文

纯css实现瀑布流! 附源码!!!

瀑布流用于展示图片信息,我这里用的背景颜色来代替图片

PC端效果

源码(直接复制粘贴就可以运行了!!!)

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>PC端瀑布流</title>
    <style>
        .box {
            width: 1200px;
            margin: 0 auto;
            /* 几列 */
            column-count: 4;
            /* 列间距 */
            column-gap: 20px;
            /* 添加背景颜色 */
            background-color: #f5f5f5;
            padding: 20px;
            border-radius: 10px;
        }

        .box div {
            height: 160px;
            margin-bottom: 20px; /* 增加底部间距 */
            /* 避免在该元素内部发生分页或者分栏 如果不够 排在下一列*/
            break-inside: avoid;
            color: #333333; /* 更改文字颜色 */
            text-align: center;
            font-size: 24px; /* 调整字体大小 */
            border: 2px solid #ffffff; /* 添加边框 */
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); /* 添加阴影效果 */
            border-radius: 10px; /* 圆角 */
        }

        .box div:nth-child(1) {
            background: linear-gradient(135deg, #ffcc00, #ff9900);
        }

        .box div:nth-child(2) {
            background: linear-gradient(135deg, #ff6666, #ff3333);
        }

        .box div:nth-child(3) {
            background: linear-gradient(135deg, #66ccff, #3399ff);
        }

        .box div:nth-child(4) {
            background: linear-gradient(135deg, #ccff66, #99ff33);
        }

        .box div:nth-child(5) {
            background: linear-gradient(135deg, #ffccff, #ff99cc);
        }

        .box div:nth-child(6) {
            background: linear-gradient(135deg, #ccffcc, #99ff99);
        }

        .box div:nth-child(7) {
            background: linear-gradient(135deg, #ffcc99, #ff9966);
        }

        .box div:nth-child(8) {
            background: linear-gradient(135deg, #ccccff, #9999ff);
        }

        .box div:nth-child(9) {
            background: linear-gradient(135deg, #ffcccc, #ff9999);
        }

        .box div:nth-child(10) {
            background: linear-gradient(135deg, #ccffcc, #99ff99);
        }

        .box div:nth-child(11) {
            background: linear-gradient(135deg, #ffcc99, #ff9966);
        }

        .box div:nth-child(12) {
            background: linear-gradient(135deg, #ccccff, #9999ff);
        }

        .box div:nth-child(13) {
            background: linear-gradient(135deg, #ffcccc, #ff9999);
        }

        .box div:nth-child(14) {
            background: linear-gradient(135deg, #ccffcc, #99ff99);
        }

        .box div:nth-child(15) {
            background: linear-gradient(135deg, #ffcc99, #ff9966);
        }

        .box div:nth-child(16) {
            background: linear-gradient(135deg, #ccccff, #9999ff);
        }

        .box div:nth-child(2n) {
            height: 300px;
        }

        .box div:nth-child(3n+1) {
            height: 180px;
        }
    </style>
</head>

<body>
    <div class="box">
        <div>1</div>
        <div>2</div>
        <div>3</div>
        <div>4</div>
        <div>5</div>
        <div>6</div>
        <div>7</div>
        <div>8</div>
        <div>9</div>
        <div>10</div>
        <div>11</div>
        <div>12</div>
        <div>13</div>
        <div>14</div>
        <div>15</div>
        <div>16</div>
    </div>
</body>

</html>

扫码进群领前端资料

请添加图片描述

移动端效果

源码(直接复制粘贴就可以运行了!!!)

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>H5 瀑布流</title>
    <style>
        .lists {
            padding: 20px;
            box-sizing: border-box;
            column-count: 2;
            column-gap: 10px;
        }

        .item {
            break-inside: avoid;
            width: auto;
            height: 200px;
            background-color: #eee;
            line-height: 200px;
            text-align: center;
            margin-bottom: 10px;
        }

        .lists .item:nth-child(2n+1) {
            height: 240px;
        }

        .lists .item:nth-child(3n+1) {
            height: 320px;
        }

        .lists .item:nth-child(1) {
            background: linear-gradient(135deg, #ffcc00, #ff9900);
        }

        .lists .item:nth-child(2) {
            background: linear-gradient(135deg, #ff6666, #ff3333);
        }

        .lists .item:nth-child(3) {
            background: linear-gradient(135deg, #66ccff, #3399ff);
        }

        .lists .item:nth-child(4) {
            background: linear-gradient(135deg, #ccff66, #99ff33);
        }

        .lists .item:nth-child(5) {
            background: linear-gradient(135deg, #ffccff, #ff99cc);
        }

        .lists .item:nth-child(6) {
            background: linear-gradient(135deg, #ccffcc, #99ff99);
        }

        .lists .item:nth-child(7) {
            background: linear-gradient(135deg, #ffcc99, #ff9966);
        }

        .lists .item:nth-child(8) {
            background: linear-gradient(135deg, #ccccff, #9999ff);
        }

        .lists .item:nth-child(9) {
            background: linear-gradient(135deg, #ffcccc, #ff9999);
        }

        .lists .item:nth-child(10) {
            background: linear-gradient(135deg, #ccffcc, #99ff99);
        }

        .lists .item:nth-child(11) {
            background: linear-gradient(135deg, #ffcc99, #ff9966);
        }

        .lists .item:nth-child(12) {
            background: linear-gradient(135deg, #ccccff, #9999ff);
        }

        .lists .item:nth-child(13) {
            background: linear-gradient(135deg, #ffcccc, #ff9999);
        }

        .lists .item:nth-child(14) {
            background: linear-gradient(135deg, #ccffcc, #99ff99);
        }

        .lists .item:nth-child(15) {
            background: linear-gradient(135deg, #ffcc99, #ff9966);
        }
    </style>
</head>

<body>
    <div class="lists">
        <div class="item">1</div>
        <div class="item">2</div>
        <div class="item">3</div>
        <div class="item">4</div>
        <div class="item">5</div>
        <div class="item">6</div>
        <div class="item">7</div>
        <div class="item">8</div>
        <div class="item">9</div>
        <div class="item">10</div>
        <div class="item">11</div>
        <div class="item">12</div>
        <div class="item">13</div>
        <div class="item">14</div>
        <div class="item">15</div>
    </div>
</body>

</html>

http://www.kler.cn/news/362104.html

相关文章:

  • 【C++篇】探索STL之美:熟悉使用String类
  • 删除本地文件不影响Github
  • [云] 创建 Docker 镜像,将其推送到 Amazon Elastic Container Registry (ECR),并对已部署的应用程序进行负载测试
  • 【KEIL那些事 4】CMSIS缺失!!!!导致不能编译!!!!软件自带芯片下载缓慢!!!!!!快速下载芯片包!!!!!
  • 【平方矩阵 + 蛇形矩阵】
  • 基于SpringBoot+Vue+uniapp微信小程序的澡堂预订的微信小程序的详细设计和实现
  • Android Studio Gradle版本、插件以及Android API对应关系(持续更新)
  • 二百六十八、Kettle——同步ClickHouse清洗数据到Hive的DWD层静态分区表中(每天一次)
  • docker 误删gitlab文件,另类的删库跑路,如何进行恢复?
  • css 不管目录结构层级。父元素有很多块子元素,孙子元素。希望从左往右从上往下排列
  • MySQL程序介绍<二>
  • TensorRT推理端到端
  • Nodejs上传阿里云oss图片案例
  • jupyter notebook 笔记
  • uniapp-components(封装组件)
  • 可能不常用到的Git命令
  • Springboot实现阿里云短信验证服务+Redis缓存
  • 手撕布隆过滤器:原理解析与面试心得
  • QT-子项目管理
  • 【JavaScript fetch API】简介和使用
  • 牛只行为及种类识别数据集18g牛只数据,适用于多种图像识别,目标检测,区域入侵检测等算法作为数据集。数据集中包括牛只行走,站立,进食,饮水等不同类型的数据
  • SpringBoot接收RequestBody数据时,参数大写接收不到数据以及解决办法
  • pm2 守护http-server
  • Redis Search系列 - 第二讲 同义词
  • Go 项目配置的定制化和一体化打包方案
  • 红队老子养成记4 - 不要遇到403就放弃,学会403绕过,找到别人找不到的接口!!(全网最多绕过!)