html&css反向悬停效果案例

此博客介绍了如何使用HTML和CSS创建一个反向悬停效果的导航菜单。通过CSS的transform属性和过渡效果,当鼠标悬停在链接上时,背景颜色从右侧向左侧平滑展开。代码示例中展示了不同颜色的链接在悬停时的变化,适用于网页设计和前端开发的学习者。

接下来练习反向悬停效果案例

代码如下:

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title></title>
	<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
 <ul>
 	<li><a href="#">首页</a></li>
 	<li><a href="#">首页1</a></li>
 	<li><a href="#">首页2</a></li>
 	<li><a href="#">首页3</a></li>
 	<li><a href="#">首页4</a></li>
 </ul>
</body>
</html>

CSS代码:

body
{
	margin: 0;
	padding: 0;
	background: #262626;
}
ul
{
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%,-50%);
	margin: 0;
	padding: 0;
	display: flex;
}
ul li
{
    list-style: none;
}
ul li a
{
	position: relative;
	display: block;
	width: 150px;
	height: 80px;
	line-height: 80px;
	text-align: center;
	font-size: 16px;
	color: #fff;
	font-family: sans-serif;
	text-decoration: none;
	border: 1px solid #000;
	border-right: none;
	transition: .5s;
}
ul li:last-child a 
{
	border-right: 1px solid #000;
}
ul li a:before
{
	content: '';
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background: #f00;
	overflow: hidden;
	z-index: -1;
	transform: scaleX(0);
	transform-origin: right;
	transition: transform 0.5s ease-in-out;
}
ul li a:hover:before
{
   transform: scaleX(1);
   transform-origin: left;
}
ul li:nth-child(1) a:before
{
	background: #3b5999;
}
ul li:nth-child(2) a:before
{
	background: #55acee;
}
ul li:nth-child(3) a:before
{
	background: #dd4b39;
}
ul li:nth-child(4) a:before
{
	background: #0077B5;
}
ul li:nth-child(5) a:before
{
	background: #e4405f;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值