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>
相关推荐
爱勇宝1 分钟前
鸿蒙生态的下半场:开发者不只要能开发,还要能赚钱
android·前端·程序员
IT_陈寒3 小时前
SpringBoot这个自动配置坑我跳了三次
前端·人工智能·后端
kyriewen3 小时前
我用 AI 一周写完了整个项目,上线第一天就崩了——这是我踩过最贵的 5 个坑
前端·javascript·ai编程
牧艺4 小时前
从零到协同:构建类飞书在线文档系统的五个技术重难点
前端·人工智能
红尘散仙4 小时前
想写一个像样的终端 App?试试把 React 的开发体验搬进 Rust TUI
前端·rust
袋鼠云数栈UED团队5 小时前
一套 Spec-First 的 AI 编程工作流
前端·人工智能
袋鼠云数栈前端5 小时前
一套 Spec-First 的 AI 编程工作流
前端·ai+
angerdream5 小时前
Android手把手编写儿童手机远程监控App之vue3 路由守卫
前端
不服老的小黑哥5 小时前
AI规范驱动编程-harness工程项目实战
前端
vivo互联网技术5 小时前
从 Web 到桌面:基于 Tauri 2.0 + Vue 3 打造 vivo 线下门店「大头贴」拍照体验系统
前端·rust