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>
相关推荐
小小小小宇3 小时前
前端 Service Worker
前端
只喜欢赚钱的棉花没有糖3 小时前
http的缓存问题
前端·javascript·http
小小小小宇4 小时前
请求竞态问题统一封装
前端
loriloy4 小时前
前端资源帖
前端
源码超级联盟4 小时前
display的block和inline-block有什么区别
前端
蓝婷儿4 小时前
Python 爬虫入门 Day 2 - HTML解析入门(使用 BeautifulSoup)
爬虫·python·html
GISer_Jing4 小时前
前端构建工具(Webpack\Vite\esbuild\Rspack)拆包能力深度解析
前端·webpack·node.js
让梦想疯狂4 小时前
开源、免费、美观的 Vue 后台管理系统模板
前端·javascript·vue.js
海云前端4 小时前
前端写简历有个很大的误区,就是夸张自己做过的东西。
前端
葡萄糖o_o4 小时前
ResizeObserver的错误
前端·javascript·html