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>
相关推荐
东方小月6 小时前
从零开发一个 Coding Agent(四):使用状态机校验大模型事件流
前端·人工智能·后端
Csvn6 小时前
🧩 ESM vs CJS 混用的 7 个「天坑」——从 TypeScript 编译到 Node 与浏览器
前端
Csvn6 小时前
🎯 Web 性能 API 集合:Performance Observer 的 5 个冷门妙用
前端
Csvn6 小时前
深入 React 闭包陷阱:从根源上理解并根治 stale closure
前端
whyfail6 小时前
前端学 Spring Boot(8):接口为什么越用越慢?
前端·spring boot·后端
用户059540174467 小时前
LangChain 记忆测试踩坑实录:这两个坑让我排查了 4 小时
前端·css
程序员黑豆7 小时前
鸿蒙应用开发:@Monitor 装饰器使用教程
前端·harmonyos
SamChan908 小时前
在Web应用中集成PDF多语言翻译功能:PDFTranslator API实战指南
前端·python·ai·pdf·yapi·机器翻译
kyriewen8 小时前
AI Agent 9秒删光了生产数据库——我给自己的项目做了5个紧急检查
前端·ai编程·claude
IT_陈寒8 小时前
JavaScript的this又双叒叕让我怀疑人生了
前端·人工智能·后端