当前位置: 代码迷 >> HTML/CSS >> css上拉菜单
  详细解决方案

css上拉菜单

热度:494   发布时间:2012-10-09 10:21:45.0
css下拉菜单
#header {
position: relative;
width: 100%;
font: 12px normal Arial, Helvetica, sans-serif;
    z-index:1;
}

#header .disclaimer a {
color: #ccc;
}

#header img {
/*margin: 20px 0 10px;*/
}

ul.topnav {
list-style: none;
padding: 0 20px 0 20px;
margin: 0px;
float: left;
    width:96%;
font-size: 1.2em;
background: url(/resources/images/topnav_bg.gif) repeat-x;
}

ul.topnav li {
float: left;
margin: 0;
padding: 0 15px 0 0;
position: relative; /*--Declare X and Y axis base--*/
}

ul.topnav li a {
padding: 10px 5px;
color: #fff;
display: block;
text-decoration: none;
float: left;
}

ul.topnav li a:hover {
/*background: url(topnav_hover.gif) no-repeat center top;*/
}

ul.topnav li span {
width: 17px;
height: 35px;
float: left;
background: url(/resources/images/subnav_btn.gif) no-repeat center top;
}

ul.topnav li span.subhover {
background-position: center bottom;
cursor: pointer;
}

/*--Hover effect for trigger--*/
ul.topnav li ul.subnav {
list-style: none;
position: absolute; /*--Important - Keeps subnav from affecting main navigation flow--*/
left: 0;
top: 35px;
background: #336699;
margin-top: -4px;
padding: 0;
display: none;
float: left;
width: 170px;
border-left: 1px solid #4682b4; /*--Create bevel effect--*/
border-right: 1px solid #4682b4; /*--Create bevel effect--*/
-moz-border-radius-bottomleft: 5px;
-moz-border-radius-bottomright: 5px;
-webkit-border-bottom-left-radius: 5px;
-webkit-border-bottom-right-radius: 5px;
}

ul.topnav li ul.subnav li {
margin: 0;
padding: 0;
border-bottom: 1px solid #4682b4; /*--Create bevel effect--*/
clear: both;
width: 170px;
}

html ul.topnav li ul.subnav li a {
float: left;
width: 145px;
background: #6490bb no-repeat 10px center;
padding-left: 20px;
}

html ul.topnav li ul.subnav li a:hover {
/*--Hover effect for subnav links--*/
background: #C9C9A7 no-repeat 10px center;
color: black;
}
<div id="header">
    <ul class="topnav">
        <li><a href="javascript:">人员管理</a>
            <ul class="subnav">
                <li><a href="./ChangePassword.do">修改密码</a></li>
                <li><a href="./UserLoginLogList.do">操作日志</a></li>
            </ul>
        </li>
        <li><a href="javascript:">服务管理</a>
            <ul class="subnav">
                <li><a href="./ServiceRegisterList.do">服务注册</a></li>
                <li><a href="./ServiceLogList.do">服务日志</a></li>
                <li><a href="./ListServiceStatus.do">服务监控</a></li>
            </ul>
        </li>
        <li><a href="#">关于</a></li>
    </ul>
</div>
<script type="text/javascript">
    $(document).ready(function() {
        $("ul.topnav > li").append("<span></span>").bgiframe();
        $("ul.topnav li span,ul.topnav li a").click(
                                    function() {
                                        $(this).parent().find("ul.subnav").show();
                                        $(this).parent().hover(function() {
                                            $(this).parent().find("ul.subnav").hide();
                                        });
                                    })
                .hover(
                      function() {
                          $(this).addClass("subhover");
                      },
                      function() {
                          $(this).removeClass("subhover");
                      }
                );
        // 显示出注销按钮.
        $(".header_links").show();

        // 将content_div的高度加大.
        var aoffset = $("#bottom_div").offset();
        var boffset = $("#content_div").offset();
        $("#content_div").height(aoffset.top - boffset.top);

        // 给主体内容表格加入鼠标高亮
        addTableHighlight();
    });
    /*列表加入鼠标高亮*/
    function addTableHighlight() {
        $(".table tbody tr").mouseover(
                                      function() {
                                          $(this).addClass("over");
                                      }).mouseout(function() {
            $(this).removeClass("over");
        });
    }
    /*列表分页ajax读取完成函数,必须实现*/
    function ajaxLoadComplete(){
          addTableHighlight();
    }
</script>
<!-- 主页面内容开始 -->
<div id="content_div" class="wrapper">
  相关解决方案