web前端——HTML+CSS实现九宫格

web前端------HTML+CSS实现九宫格

html 复制代码
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        body {
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            background: rgb(224, 212, 203);
        }
        
        .container {
            width: 300px;
            height: 300px;
            display: flex;
            flex-wrap: wrap;
        }
        
        .container .item {
            position: relative;
            box-sizing: border-box;
            width: 100px;
            height: 100px;
            border: 2px solid white;
            background-image: url(A.jpg);
            background-size: 300px 300px;
        }
        
        .container .item:nth-child(3n+1) {
            left: -10px;
        }
        
        .container .item:nth-child(3n+2) {
            left: 0px;
            background-position-x: -100px;
        }
        
        .container .item:nth-child(3n+3) {
            left: 10px;
            background-position-x: -200px;
        }
        
        .container .item {
            top: 10px;
            background-position-y: -200px;
        }
        
        .container .item:nth-child(-n+6) {
            top: 0px;
            background-position-y: -100px;
        }
        
        .container .item:nth-child(-n+3) {
            top: -10px;
            background-position-y: 0px;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
    </div>
</body>

</html>
相关推荐
小皮虾13 分钟前
小程序首页性能优化实战:从 4 秒到 1.8 秒
前端·微信小程序
山河木马15 分钟前
GPU自动处理专题1-裁剪到底在裁什么(裁剪)
前端·webgl·计算机图形学
奔跑的蜗牛ing17 分钟前
CentOS Nginx 安装与静态文件服务器配置指南
前端·面试·架构
子兮曰29 分钟前
Bun 重写为 Rust:11天、64个Claude、16.5万美元,一次改变行业认知的激进实验
前端·后端·bun
子兮曰34 分钟前
Node.js v26.5.0 深度解读:import Text、流式 ReadableStreamTee、以及隐藏的安全加固浪潮
前端·后端·node.js
子兮曰37 分钟前
TypeScript 7.0 RC 深度解读:Go 重写完成,10 倍提速,编译器的「奇点时刻」
前端·后端·typescript
还有多久拿退休金43 分钟前
让飞书知识库跟着 commit 自己长:一套自动化知识库的真实实现
前端·算法·架构
喝拿铁写前端1 小时前
AI 时代,ESLint 应该怎么做得更好
前端·人工智能·代码规范
妙码生花2 小时前
从 PHP 到 AI + Golang,程序员自救转型手记(二十七):管理员登录验证码开关
前端·后端·ai编程
尼斯湖皮皮怪2 小时前
iceCoder 记忆系统深度分析
前端·javascript