DIV+CSS布局重新学习之css控制ul li实现2级菜单

本文介绍了一种使用HTML和JavaScript实现的竖状菜单,包括鼠标悬停时子菜单的显示与隐藏效果。该菜单适用于网站导航栏设计,通过简单的代码实现了良好的交互体验。

 

竖状菜单:

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript"><!--//--><![CDATA[//><!--
startList = function() {
    if (document.all&&document.getElementById) {
        navRoot = document.getElementById("menu");
        var allli = navRoot.getElementsByTagName("li")
        for (i=0; i<allli.length; i++) {
            node = allli[i];
            node.onmouseover=function() {
                this.className+=" current";
            }
            node.onmouseout=function() {
                this.className=this.className.replace(" current", "");
            }
        }
    }
}
window.onload=startList;
//--><!]]></script>
<style type="text/css">
body { font-family: Verdana; font-size: 12px; line-height: 1.5; }
img { border-style: none; }
a { color: #000; text-decoration: none; }
a:hover { color: #F00; }
#menu { width: 100px; border: 1px solid #CCC; border-bottom:none;}
#menu ul { list-style: none; margin: 0px; padding: 0px; }
#menu ul li { background: #eee; padding: 0px 8px; height: 26px; line-height: 26px; border-bottom: 1px solid #CCC; position:relative; }

#menu ul li ul { display:none; position: absolute; left: 100px; top: 0px; width:100px; border:1px solid #ccc; border-bottom:none; }
#menu ul li.current ul { display:block;}
#menu ul li:hover ul { display:block;}
</style>
</head>
<body>
    <div id="menu">
        <ul>
            <li><a href="#">首页</a></li>
            <li><a href="#">网页版式布局</a>
                <ul>
                <li><a href="#">自适应宽度</a></li>
                <li><a href="#">固定宽度</a></li>
                </ul>
            </li>
            <li><a href="#">div+css教程</a>
                <ul>
                <li><a href="#">新手入门</a></li>
                <li><a href="#">视频教程</a></li>
                <li><a href="#">常见问题</a></li>
                </ul>
            </li>
            

转载于:https://www.cnblogs.com/yangzhilong/p/3811992.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值