CSS布局案例 6-51 网页图片悬停效果


前言

使用css3实现网页图片悬停效果。


实现过程

1.步骤

网页图片悬停效果实现步骤:
	  1、先作一个区域,放置上图片,设置图片鼠标悬停时的蒙版效果
	  2、然后做标题和两个图片
	  3、使用绝对定位的方式,起始时将三个内容放置在区域外侧,悬停时使用过渡动画移动到区域内部

2.代码

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>网页图片鼠标悬停效果</title>
		<style type="text/css">
			*{
				margin: 0;
				padding: 0;
			}
			.box{
				width: 1300px;
				height: 866px;
				margin: 300px auto;
				position: relative;
				/* 将区域外边的文字和图片隐藏 */
				overflow: hidden;
			}
			.box img:nth-of-type(1){
				width: 1300px;
				height: 866px;
			}
			.bg{
				position: absolute;
				width: 1300px;
				height: 866px;
				background-color: black;
				top: 0;
				opacity: 0;
			}
			/* 设置透明度蒙版 */
			.box:hover .bg{
				opacity: 0.7;
			}
			/* 标题起始在区域的外边,鼠标悬停时进入区域 */
			.titles{
				position: absolute;
				width: 1300px;
				font-size: 70px;
				color: white;
				text-align: center;
				top: -100px;
				transition: all .5s linear;
			}
			.box:hover .titles{
				top: 100px;
			}
			/* 左侧图片动画与标题类似 */
			.box img:nth-of-type(3){
				position: absolute;
				width: 300px;
				height: 300px;
				top: 360px;
				left: -350px;
				transition: all .5s linear;
			}
			.box:hover img:nth-of-type(3){
				left: 500px;
			}
			/* 右侧图片动画与标题类似 */
			.box img:nth-of-type(2){
				position: absolute;
				width: 150px;
				height: 150px;
				top: 440px;
				right: -350px;
				transition: all .5s linear;
				z-index: 1;
			}
			.box:hover img:nth-of-type(2){
				right: 570px;
			}
		</style>
	</head>
	<body>
		<div class="box">
			<img src="images/woshou.jpg" />
			<!-- 设置图片鼠标悬停时的蒙版 -->
			<p class="bg"></p>
			<h3 class="titles">商业资讯规划</h3>
			<img src="images/搜索.png" />
			<img src="images/圆.png" />
		</div>
	</body>
</html>


3.效果

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值