0

我正在尝试使用 CSS3、锚标签和 :target 伪类构建一个水平手风琴导航菜单。我几乎解决了。我只需要一些方法来设置顶级列表项以显示在页面加载中。

jsfiddle在这里:http: //jsfiddle.net/4jpowell/nzAsr/4/

<!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
.nav {
    border: 1px solid blue;
}
.menu, .menu * {
    margin: 0;
    padding: 0;
    list-style: none;
}
.menu a:link {
    color: #9D0C0C; 
}
.menu a {
    margin: 0 10px 0 0;
    text-decoration: none;
    display: block;
    padding: 0.25em;
    border: 2px solid #9D0C0C;
    position: static;
    font-size: 1.1em;
    font-family: "Courier New", Courier, monospace;
    font-weight: bold;
    text-transform: uppercase;
    float: left;
    overflow: hidden;
}
/*top level link is selected*/
/*hide other top level links*/
.menu > li:not(:target) {
    display: none;
}
/*expand*/
    li:target .subnav {
    display: block;
}
/*default*/
.menu > li {
    display: block;
}
.subnav {
    display: none;
    float: left;
    overflow: hidden;
}
/*level 2 nav links*/
    li ul li {
    float: left;
}
</style>
</head>
<body>
    <div class="nav">
        <ul class="menu">
            <li id="about">
                <a href="#about">About</a>
                <ul class="subnav">
                    <li><a href="#">Mission</a></li>
                    <li><a href="#">Press</a></li>
                </ul>
            </li>
            <li id="events">
                <a href="#events">Events</a>
                <ul class="subnav">
                    <li><a href="#">Upcoming Events</a></li>
                    <li><a href="#">Past Events</a></li><li><a href="#">Press</a></li>
                </ul>
            </li>
            <li id="programs">
                <a href="#programs">Programs</a>
                <ul class="subnav">
                    <li><a href="#">Festival</a></li>
                    <li><a href="#">Performance</a></li>
                    <li><a href="#">Public Arts</a></li>
                    <li><a href="#">Oral History</a></li>
                </ul>
            </li>
        </ul>
    </div>
<script>
    $(window).trigger('hashchange');
    });
</script>
</body>
</html>
4

1 回答 1

0

您可以使用 jQuery Accordian UI 来完成。 链接在这里

于 2013-06-20T04:53:59.413 回答