纯css制作瀑布流

<div class="masonry">
		<div class="item">
			<img src="http://picsum.photos/360/460?random=1" >
		</div>
		<div class="item">
			<img src="http://picsum.photos/360/500?random=1" >
		</div>
		<div class="item">
			<img src="http://picsum.photos/360/420?random=1" >
		</div>
		<div class="item">
			<img src="http://picsum.photos/360/480?random=1" >
		</div>
		<div class="item">
			<img src="http://picsum.photos/360/350?random=1" >
		</div>
		<div class="item">
			<img src="http://picsum.photos/360/420?random=1" >
		</div>
		<div class="item">
			<img src="http://picsum.photos/360/435?random=1" >
		</div>
		<div class="item">
			<img src="http://picsum.photos/360/410?random=1" >
		</div>
		<div class="item">
			<img src="http://picsum.photos/360/460?random=1" >
		</div>
		<div class="item">
			<img src="http://picsum.photos/320/200?random=1" >
		</div>
		<div class="item">
			<img src="http://picsum.photos/360/470?random=1" >
		</div>
		<div class="item">
			<img src="http://picsum.photos/256/456?random=1" >
		</div>
		<div class="item">
			<img src="http://picsum.photos/288/265?random=1" >
		</div>
	</div>

http://picsum.photos/360/460?random=1这是浏览器随机生成的一张图片,360是宽,460是高。

*{
			margin: 4px;
			font-family: helvetica;
			padding: 0;
		}
		.masonry{
			column-count: 4;
			column-gap: 0;
		}
		.item{
			padding: 2px;
			box-sizing: border-box;
			position: relative;
			counter-increment: item-counter;
		}
		.item img{
			display: block;
			width: 100%;
			height: auto;
		}
		.item::after{
			position: absolute;
			display: block;
			top: 0;
			left: 0;
			width: 24px;
			height: 24px;
			background-color: #000;
			line-height: 24px;
			text-align: center;
			color: #fff;
			content: counter(item-counter);
		}

或者是

*{
			margin: 4px;
			padding: 0;
		}
		.masonry{
			display: flex;
			flex-direction: column;
			flex-wrap: wrap;
			height: 1000px;
		}
		.item img{
			display: block;
			width: 100%;
			height: auto;
		}
		.item{
			width: 25%;
			padding: 2px;
			box-sizing: border-box;
			position: relative;
			counter-increment: item-counter;
		}
		.item::after{
			position: absolute;
			display: block;
			top: 0;
			left: 0;
			width: 24px;
			height: 24px;
			background-color: #000;
			line-height: 24px;
			text-align: center;
			color: #fff;
			content: counter(item-counter);
		}
		.item:nth-child(4n+1){
			order: 1;
		}
		.item:nth-child(4n+2){
			order: 2;
		}
		.item:nth-child(4n+3){
			order: 3;
		}
		.item:nth-child(4n+4){
			order: 4;
		}

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值