垂直菜单的实现(使用hovor+无序列表)

27 篇文章 0 订阅

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>导航菜单</title>
		<style type="text/css">
			* {
				margin: 0;
				padding: 0;
				font-size: 14px;
			}
			ul {
				list-style: none;
				width: 100px
			}
			a {
				color: #333;
				text-decoration: none
			}
			.nav li a {
				display: block;
				text-indent: 20px;
				height: 30px;
				line-height: 30px;
				width: 100px;
				background-color: #efefef;
				margin-bottom: 1px;
			}
			.nav li a:hover {
				background-color: #F60;
				color: #fff
			}
		</style>
	</head>
	<body>
		<ul class="nav">
			<li><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>
	</body>
</html>

===================================

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>水平导航菜单</title>
		<style type="text/css">
			* {
				margin: 0;
				padding: 0;
				font-size: 14px;
			}
			ul {
				list-style: none;
			}
			a {
				color: #333;
				text-decoration: none
			}
			li {
				float:left; // 浮动菜单item
			}
			/* 文本缩进,不影响整体的宽度:text-indent: 20px; */
			.nav li a {
				display: block;
				height: 30px;
				line-height: 30px;
				width: 100px;
				background-color: darkslategray;
				margin-left: 2px;
				text-align: center;
			}
			.nav li a:hover {
				background-color: #F60;
				color: #fff
			}
		</style>
	</head>
	<body>
		<ul class="nav">
			<li><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>
	</body>
</html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>导航菜单</title>
<style type="text/css">
*{margin:0; padding:0; font-size:14px;}
a{color:#333;text-decoration:none}
.nav{list-style:none; height:30px; border-bottom:10px solid #F60; margin-top:20px; padding-left:50px;}
.nav li{float:left}
.nav li a{display:block; height:30px;text-align:center; line-height:30px; width:120px; background:url(http://img.mukewang.com/53846438000168f901200060.jpg); margin-left:1px;}
.nav li a.on, .nav li a:hover{ background-position: 0 -30px; color:#fff;}
</style>
</head>
<body>

<ul class="nav">
    <li><a class="on" href="#">首  页</a></li>
    <li><a href="#">新闻快讯</a></li>
    <li><a href="#">产品展示</a></li>
    <li><a href="#">售后服务</a></li>
    <li><a href="#">联系我们</a></li>
  </ul>
</body>
</html>

切换时,变化菜单的宽高例子,使用js或jquery控制item的宽高。

<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>水平,圆角导航菜单</title>
		<style type="text/css">
			* {
				margin: 0;
				padding: 0;
				font-size: 14px;
			}

			ul {
				list-style: none;
				height: 30px;
				margin-top: 20px;
				border-bottom: 5px solid #f60;
				padding-left: 30px;
			}

			a {
				color: #333;
				text-decoration: none
			}

			.nav li {
				float: left; // 浮动菜单item
				padding-top: 20px;
			}

			/* 文本缩进,不影响整体的宽度:text-indent: 20px; */
			.nav li a {
				display: block;
				height: 30px;
				line-height: 30px;
				width: 100px;
				background-color: yellowgreen;
				margin-right: 3px;
				text-align: center;
			}

			/* on默认状态,和鼠标选中状态是一样的 */
			.nav li a:hover {
				margin-top: -10px;
				height: 40px;
				color: #fff;
				line-height: 40px;
			}
		</style>
		<!-- 使用jquery替代js,实现菜单动画效果。代码简化 -->
		<!-- <script type="text/javascript" src="js/jquery-1.2.6.min.js"></script>
		<script type="text/javascript">
			$(function(){
				$('a').hover {
					function(){
						$(this).stop().animate({"width":"160px"}, 200);
					},
					function(){
						$(this).stop().animate({"width":"120px"}, 200);
					}
				}
			})
		</script> -->
		<script type="text/javascript">
			window.onload = function() {
				var aA = document.getElementsByTagName('a');
				for (var i = 0; i < aA.length; i++) {
					// 添加mouseOver事件
					aA[i].onmouseover = function() {
						clearInterval(this.time);
						var This = this;
						This.time = setInterval(function() {
							This.style.width = This.offsetWidth + 8 + "px";
							if (This.offsetWidth >= 120) {
								clearInterval(This.time);
							}
						}, 30);
					};
					aA[i].onmouseout = function() {
						clearInterval(this.time);
						var This = this;
						This.time = setInterval(function() {
							This.style.width = This.offsetWidth - 8 + "px";
							if (This.offsetWidth <= 120) {
								This.style.width = "120px";
								clearInterval(This.time);
							}
						}, 30);
					};
				}
			}
		</script>
	</head>
	<body>
		<ul class="nav">
			<li><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>
	</body>
</html>

=======中英文切换菜单实现======

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <style type="text/css">
        .top-nav
        {
            font-size: 12px;
            font-weight: bold;
            list-style: none;
            border-bottom: 8px solid #DC4E1B;
            overflow: auto;
        }
        .top-nav li
        {
            float: left;
            margin-right: 1px;
        }
        .top-nav li a
        {
            line-height: 20px;
            text-decoration: none;
            background: #DDDDDD;
            color: #666666;
            display: block;
            width: 80px;
            text-align: center;
        }
        /*设置正常状态英文菜单隐藏*/
         .top-nav li a span{
             display:none;
         }
        /*鼠标移动到链接上面时将英文菜单显示*/
        .top-nav li:hover a span{
             display:block;
             background:#DC4E1B;
             color:white;
         }
        /*鼠标移动到链接上面时将中文菜单位置上移*/
         .top-nav li:hover a {
            margin-top:-20px;
         }
    </style>
</head>
<body>
    <ul class="top-nav">
        <li><a href="#">首页<span>Home</span></a></li>
        <li><a href="#">课程大厅<span>Course</span></a></li>
        <li><a href="#">学习中心<span>Learn</span></a></li>
        <li><a href="#">关于我们<span>About</span></a></li>
    </ul>
</body>
</html>

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值