带滑动条的导航栏(上)---CSS实现样式

前言

   本系列实现的是带有滑动条的导航栏,效果图如下

   

  我看其它的网站,对比之下还是喜欢这种简洁大方的感觉,于是乎扒拉下来了。

布局层

   首先,我新建了一个navigator1.html,先用div布局,如下

   

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>滑动条导航栏</title>
		<style type="text/css">
			body{margin: 0; }
			ul, li{margin: 0; padding: 0;}
			a{text-decoration: none;}
			.banner{
				width: 100%;
				height: 70px;
				background-color: yellow;
				}
			.nav-box{
				width: 50%;
				float: right;
				position: relative;
				top: 40px;
				background-color: darkgray;
			}
			.nav-box ul{
				list-style: none;
			}
			.nav-box ul li{
				float: left;
				font-size: 14px;
				font-family: "微软雅黑";
				height: 30px;
				line-height: 30px;
				padding: 0 12px;
				background-color: #F5F5F5;
			}	
		</style>
	</head>
	<body>
		<div class="banner" >
			<div class="nav-box">
				<ul>
					<li class="cur"><a href="#">首页</a></li>
					<li><a href="#">论坛</a></li>
					<li><a href="#">商务合作</a></li>
					<li><a href="#">下载专区</a></li>
					<li><a href="#">关于我们</a></li>
				</ul>
			</div>
		</div>
	</body>
</html>

   编写完上述代码,效果如下

  

 上图已经将高度标明,已看便知。其中的position前几节已经讲过。

添加导航条

   下面为navigator1.html全部内容

   

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>滑动条导航栏</title>
		<style type="text/css">
			body{margin: 0; }
			ul, li{margin: 0; padding: 0;}
			a{text-decoration: none;}
			.banner{
				width: 100%;
				height: 70px;
			/*	background-color: yellow;*/
				}
			.nav-box{
				width: 50%;
				float: right;
				position: relative;
				top: 40px;
				/*background-color: darkgray;*/
			}
			.nav-box ul{
				list-style: none;
			}
			.nav-box ul li{
				float: left;
				font-size: 14px;
				font-family: "微软雅黑";
				height: 30px;
				line-height: 30px;
				padding: 0 12px;
				/*background-color: #F5F5F5;*/
			}	
			.nav-box .nav-line {
			    background: none repeat scroll 0 0 #35C4FD;
			    bottom: 0;
			    font-size: 0;
			    height: 2px;
			    left: 0;
			    line-height: 2px;
			    position: absolute;
			    width: 52px;
			}	
		</style>
	</head>
	<body>
		<div class="banner" >
			<div class="nav-box">
				<ul>
					<li class="cur"><a href="#">首页</a></li>
					<li><a href="#">论坛</a></li>
					<li><a href="#">商务合作</a></li>
					<li><a href="#">下载专区</a></li>
					<li><a href="#">关于我们</a></li>
				</ul>
				<div class="nav-line" ></div>
			</div>
		</div>
	</body>
</html>

  上面添加了导航条,并且去掉了层的颜色,效果图如下

  

结语

  本节实现样式的代码不多,但是会者不难,难者不会,下一节利用jQuery实现跟随鼠标滑动


  • 5
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

玖零大壮

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值