纯css实现九宫格 带过度效果

正常效果
在这里插入图片描述
hover时的效果
鼠标停留效果

<!DOCTYPE html>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<div class="container">
			<div class="image"></div>
			<div class="image"></div>
			<div class="image"></div>
			<div class="image"></div>
			<div class="image"></div>
			<div class="image"></div>
			<div class="image"></div>
			<div class="image"></div>
			<div class="image"></div>
		</div>
	</body>
</html>
<style>
	body{
		height: 100vh;
		display: flex;
		justify-content: center; /* 相对父元素水平居中 */
		align-items: center;
		background:black;
	}
		.container{
			width: 450px;
			height: 600px;
			display: grid;
			grid-template-columns: repeat(3,1fr);
		}
		.image {
			box-shadow: inset 0 0 0 1px #fff;
			transition: 0.5s;
			background-size: 450px 600px;
			background-image: url(./queen.webp);
			position: relative;
		}
		.image:nth-child(3n+1){
			left: -25px;
			background-position-x: 0;
		}
		.image:nth-child( 3n+2 ){
			left: 0px;
			background-position-x: -150px;
		}
		.image:nth-child( 3n){
			left: 25px;
			background-position-x: -300px;
		}
		.image{
			top: 25px;
			background-position-y: -400px;
		}
		.image:nth-child(-n + 6){
			top: 0;
			background-position-y: -200px;
		}
		.image:nth-child(-n + 3){
			top: -25px;
			background-position-y: 0px;
		}
		.container:hover .image{
			left: 0;
			top:0;
			box-shadow: inset 0 0 0 0px #fff;
		}
		
</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值