【uni】微信朋友圈图片九宫格样式

html

	<view class="_contentimgList">
		<view class="wrap" v-for="(bean,index) in imgList" :key="index">
			<image :src="bean" mode="heightFix" />
		</view>
	</view>	

imgList: [图1,图1,图1,图1],//图片数组结构

css代码

._contentimgList {
				display: flex;
				flex-wrap: wrap;
				margin: 10rpx 0;


				.wrap {

					position: relative;
					overflow: hidden;
					// margin-bottom: 2%;
				}

				/*  3张图片  */
				.wrap:nth-child(1):nth-last-child(3),
				.wrap:nth-child(2):nth-last-child(2),
				.wrap:nth-child(3):nth-last-child(1) {
					width: 32%;
					image{
						height: 200rpx;
					}
				}

				/*  间隔  */
				.wrap:nth-child(2):nth-last-child(2),
				.wrap:nth-child(3):nth-last-child(1) {
					margin-left: 2%;
				}

				.wrap:not(:nth-child(1):nth-last-child(1)) img {
					position: absolute;
					top: 0;
					left: 0;
					width: 100%;
					height: 100%;
					object-fit: cover;
				}

				/*  2张图片  */
				.wrap:nth-child(1):nth-last-child(2),
				.wrap:nth-child(2):nth-last-child(1),
				/*  4张图片  */
				.wrap:nth-child(1):nth-last-child(4),
				.wrap:nth-child(2):nth-last-child(3),
				.wrap:nth-child(3):nth-last-child(2),
				.wrap:nth-child(4):nth-last-child(1) {
					width: 49%;
					image{
						height: 240rpx;
					}
				}

				/* 每行的两张图片中间间隔2%的宽度 */
				/*  2张图片  */
				.wrap:nth-child(2):nth-last-child(1),
				/*  4张图片  */
				.wrap:nth-child(2):nth-last-child(3),
				.wrap:nth-child(4):nth-last-child(1) {
					margin-left: 2%;
				}

				/*  5张以上图片  */
				.wrap:nth-child(n + 5),
				.wrap:nth-child(1):nth-last-child(n + 5),
				.wrap:nth-child(1):nth-last-child(n + 5)~.wrap {
					width: 32%;
					padding-bottom: 1%;
					image{
						height: 200rpx;
					}
				}

				.wrap:nth-child(n + 5):not(:nth-child(3n + 1)),
				.wrap:nth-child(1):nth-last-child(n + 5)~.wrap:not(:nth-child(3n + 1)) {
					margin-left: 2%;
				}

			}

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-27 18:20:02       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-27 18:20:02       106 阅读
  3. 在Django里面运行非项目文件

    2024-04-27 18:20:02       87 阅读
  4. Python语言-面向对象

    2024-04-27 18:20:02       96 阅读

热门阅读

  1. 电脑安装双系统

    2024-04-27 18:20:02       39 阅读
  2. 大模型实战:提示工程 2—基本概念和格式说明

    2024-04-27 18:20:02       35 阅读
  3. frida安装以及使用

    2024-04-27 18:20:02       33 阅读
  4. Typescript学习笔记

    2024-04-27 18:20:02       41 阅读
  5. 构建二叉树搜索树算法题总结(第三十天)

    2024-04-27 18:20:02       30 阅读
  6. 第二十六篇-Ollama-监听本地IP与端口

    2024-04-27 18:20:02       38 阅读
  7. C++: string类的模拟实现

    2024-04-27 18:20:02       33 阅读