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

[CSS] 图片九宫格

效果

在这里插入图片描述

index.html

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><title> Document </title><link type="text/css" rel="styleSheet" href="index.css" /></head><body><div class="img-container"><!--Emmet缩写: div.img-item*9 --><div class="img-item"></div><div class="img-item"></div><div class="img-item"></div><div class="img-item"></div><div class="img-item"></div><div class="img-item"></div><div class="img-item"></div><div class="img-item"></div><div class="img-item"></div></div></body>
</html>

index.css

body{width: 500px;height: 500px;margin: 0 auto;margin-top: 120px;/*设置item元素布局为网关布局*/display: flex;justify-content: center;align-items: start;background-color: #171717;padding-top: 100px;
}.img-container{width: 300px;height: 300px;/*网格布局*/ display: grid;/*网格布局列数与宽度*/ grid-template-columns: repeat(3,1fr);/*网格布局行数与高度*/ grid-template-rows: repeat(3,1fr);
}.img-item {/*添加阴影效果*/ box-shadow: inset 0 0 0 1px #fff;/*元素属性变化时平滑过度,优化视觉体验*/ transition: 0.5s;background-size: 300px 300px;/*设置背景图像*/ background-image: url(./1.png);/*相对定位*/ position: relative;
}/* 3n+1  选中第一列的元素 1 4 7*/ 
.img-item:nth-child(3n+1){background-position-x: 0;left: -20px;
}/* 3n+2  选中第二列的元素 2 5 8*/ 
.img-item:nth-child(3n + 2){background-position-x: -100%;left: 0;
}/* 3n+0  选中第三列的元素 3 6 9*/ 
.img-item:nth-child(3n){background-position-x: -200%;left: 20px;
}/* n+7  选中第三行的元素 7 8 9*/ 
.img-item:nth-child(n + 7){background-position-y: -200%;top: 20px;
}/* -n + 6 选中第一、二行的元素 6 5 4 3 2 1*/ 
.img-item:nth-child(-n + 6){background-position-y: -100%;top: 0px;
}
/* -n + 6 选中第一行的元素 3 2 1*/ 
.img-item:nth-child(-n+3){background-position-y: 0;top: -20px;
}/* 鼠标移入时修改 img-item 属性值 */ 
.img-container:hover .img-item {left: 0;top: 0;/*隐藏的阴影效果*/box-shadow: inset 0 0 0 0px #fff;
}

1.png

在这里插入图片描述

http://www.lryc.cn/news/118348.html

相关文章:

  • MChat-Gpt V1.0.0 (将ChatGpt机器人接入内网供全体使用)
  • 日常开发中Git命令指北
  • API 测试 | 了解 API 接口概念|电商平台 API 接口测试指南
  • 【计算机组成原理】24王道考研笔记——第三章 存储系统
  • 学习C语言的好处:
  • 基于k8s的devOps自动化运维平台架构设计(中英文版本)
  • P450进阶款无人机室内定位功能研测
  • 深度学习,计算机视觉任务
  • 使用 Docker 部署 canal 服务实现MySQL和ES实时同步
  • const易错详解
  • 网络安全—黑客技术【自学】
  • 作为数据产品经理的一天
  • Rust 编程小技巧摘选(7)
  • 爬虫程序中使用爬虫ip的优势
  • json-server的入门
  • uniapp调查问卷评价功能
  • Centos Linux带进度条复制(同步)文件和文件夹
  • 从数据仓库到数据结构:数据架构的演变之路
  • kafka-2.12使用记录
  • C++笔记之将定时器加入向量并设置定时器的ID为i
  • 将一组元素四舍五入到指定精度(小数位数)numpy.around()
  • tinyint这个值在MySQL中的值有哪些
  • JVM 内存结构
  • 基于百度语音识别API智能语音识别和字幕推荐系统——深度学习算法应用(含全部工程源码)+测试数据集
  • 数字万用表测量基础知识--使用DMM测量电流
  • 【BASH】回顾与知识点梳理(二十)
  • Arduino驱动SGP40空气质量传感器(气体传感器篇)
  • 识别和应对内存抖动
  • 3.3用于共享数据保护的替代工具
  • 探索数据之美:初步学习 Python 柱状图绘制