CSS制作导航做从下到上的过渡效果

记录自己遇到的一个问题:两个盒子,第二个覆盖第一个时候文字不覆盖。

方案: 外层盒子包含了 叠加的两个盒子 第一个盒子负责展示,第二个盒子定位到下方,层级设置低些以隐藏。鼠标滑过外层盒子,第二个盒子定位占据第一个盒子的位置

会覆盖了外层盒子和第一个盒子。需要提高第一个盒子的优先级,覆盖第二个盒子之上。由于第一个盒子只有文字,背景是透明的。就达到了文字会显示,背景也替换

的效果。

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style>
			

			.box1 {
				position: relative;
				display: block;
				height: 40px;
				width: 90px;
				margin: 20px 0 0 50px;
				/* background-color: #000; */
				text-align: center;
				line-height: 40px;
			}

			i {
				position: absolute;
				left: 0;
				top: 100px;
				display: block;
				width: 90px;
				height: 40px;
				background-color: #f00;
				transition: all .2s ease;
				font-style: normal;
				/* color: #fff; */
			}

			span {
				position: absolute;
				left: 0;
				top: 0;
				z-index: 2;
				display: block;
				background: rgba(0, 0, 0, 0);
				
				width: 90px;
				height: 40px;
				color: #000;
			}

			.box1:hover i {
				top: 0;
			}
		</style>
	</head>
	<body>
		

		<a class="box1">
			<span>首页</span>
			<i></i>
		</a>
	</body>
</html>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值