常见css下划线动画集合

2 篇文章 0 订阅
1 篇文章 0 订阅

引言:

导航栏下划线动画在网页设计中是非常常见的交互,下面将介绍几种非常常见,非常nice的动画特效,废话不多说直接上演示和代码。

一、效果图:

 

 二、源码如下:

<body>
		<p>样式1</p>
		<ul id="demo1">
			<li>首页</li>
			<li>产品</li>
			<li>服务</li>
			<li>关于</li>
		</ul>
		
		<p>样式2</p>
		<ul id="demo2">
			<li>首页</li>
			<li>产品</li>
			<li>服务</li>
			<li>关于</li>
		</ul>
		
		<p>样式3</p>
		<ul id="demo3">
			<li>首页</li>
			<li>产品</li>
			<li>服务</li>
			<li>关于</li>
		</ul>
		
		<p>样式4</p>
		<ul id="demo4">
			<li>首页</li>
			<li>产品</li>
			<li>服务</li>
			<li>关于</li>
		</ul>
	</body>
	<style type="text/css">
		p{
			text-align: center;
			margin: 40px 0 10px 0;
		}
		ul{
			padding: 0;
			width: 400px;
			height: 45px;
			margin:  auto;
			list-style: none;
			background-color: rgb(0,0,0,0.3);
			display: flex;
		}
		li{
			flex: 1;
			height: 100%;
			display: flex;
			align-items: center;
			justify-content: center;
			position: relative;
		}
		/***************样式1   *********/
		#demo1 li:before{
			content: '';
			position: absolute;
			width: 80%;
			left: 10%;
			bottom: 10px;
			height: 5px;
			background-color: coral;
			opacity: 0;
		}
		#demo1 li:hover:before{
			bottom: 0;
			opacity: 1;
			transition: bottom 0.3s,opacity 0.3s 0.1s;
		}
		/***************样式2   *********/
		#demo2 li:before{
			content: '';
			position: absolute;
			width: 0;
			left: 50%;
			bottom: 0;
			height: 5px;
			background-color: coral;
		}
		#demo2 li:hover:before{
			width: 80%;
			left: 10%;
			transition: all 0.5s;
		}
		/***************样式3   *********/
		#demo3 li:before{
			content: '';
			position: absolute;
			width: 0;
			left: 100%;
			bottom: 0;
			height: 5px;
			background-color: coral;
		}
		#demo3 li:hover:before{
			width: 80%;
			left: 10%;
			transition: all 0.5s;
		}
		#demo3 li:hover ~ li:before{
			left: 0;
		}
		
		/***************样式4   *********/
		#demo4 li:before{
			content: '';
			position: absolute;
			width: 0;
			left: 0;
			bottom: 0;
			height: 5px;
			background-color: coral;
		}
		#demo4 li:after{
			content: '';
			position: absolute;
			width: 0;
			right: 0;
			bottom: 0;
			height: 5px;
			background-color: coral;
		}
		#demo4 li:hover:before{
			width: 50%;
			transition: all 0.3s ease-in-out; 
		}
		#demo4 li:hover:after{
			width: 50%;
			transition: all 0.3s ease-in-out;
		}
	</style>

有些细节可能处理的不够优化,大致思路是这样的。希望对您有所微薄的帮助,也欢迎大家相互交流。

 

                                                                                                         向上的路并不拥挤,而大多数人选择了安逸——it疯子也

  • 9
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值