1

我有这个导航代码

        <div id="navigation">
        <a href="/">Home</a>
        <a href="index.php?sida=link2">link2</a>
        <a href="index.php?sida=lin3">link3</a>
        <a href="index.php?sida=link4">link4</a>
        <a href="index.php?sida=link5">link5</a>
        <a href="index.php?sida=link6">link6</a>
        <a href="index.php?sida=link7">Link7</a>
        </div>

这是导航的CSS

#navigation {
float: left;
height: 61px;
width: 885px;
background: url(../../../../images/navigation.png) no-repeat;
padding: 0 0 0 12px;

}

#navigation a {
font-size: 12px;
font-weight: bold;
float: left;
display: block;
height: 29px;
padding: 11px 30px 0 32px;
color: #FFF;
text-decoration: none;
margin: 10px 0 0 0;

}

#navigation a:hover {
background: url(../../../../images/navigation_over.png) repeat-x;   

}

#navigation a:hover.dropdown {
background: url(../../../../images/navigation_drop.gif) repeat-x;   

}

我一直在尝试学习如何为我的导航创建下拉菜单,但没有成功。

有没有好心人帮我解决这个问题。

4

2 回答 2

1

我用这个 css 创建下拉菜单:(足够老,对我来说无处不在)

.vmenu {
list-style:none;
height:75%;
min-height:24px;
width:16.67%;
max-width:544px;
min-width:90px;
text-align:center;
float:left;
z-index:1;
}
.vmenu > li {
width:100%;
list-style:none;
}
.vmenu > a {
background-color:#FFAF00;
width:100%;
height:100%;
display:block;
cursor:pointer;
}
.vmenu li > a {
background-color:#FF9F00;
display:block;
cursor:pointer;
}
.vmenu > li {
display:none;
}
.vmenu:hover > li {
display:block;
}
.vmenu > a:focus~li {
display:block;
}
/* with CSS4 which is not yes supported by any browser
it has to be handled with javascript somehow
selects the li instead of a:focus to let the tab go through
.vmenu > $li > a:focus {
display:block;
}
*/
.vmenu li > a:hover {
background-color: #2580FF;
color:#DDDDDD;
}
.vmenu li > a:focus {
background-color: #2580FF;
color:#DDDDDD;
}
.vmenu > a:hover {
background-color: #258072;
color:#DDDDDD;
}
.vmenu > a:focus {
background-color: #258072;
color:#DDDDDD;
}
.vmenu > li > ul.vmenu {
width:100%;
display:none;
}
.vmenu:hover > li > ul.vmenu {
display:block;
}
.vmenu > a:focus~li > ul.vmenu {
display:block;
}
.vmenu > li > ul.vmenu > li {
display:none;
padding:0px 0px 0px 100%;
}
.vmenu li ul.vmenu > a {
background-color:#FFAF0F;
float:left;
}
.vmenu li ul.vmenu:hover > a {
background-color:#258072;
color:#DDDDDD;
}
.vmenu li ul.vmenu > a:focus {
background-color:#258072;
color:#DDDDDD;
}
.vmenu > li > ul.vmenu:hover > li {
top:0;
display:block;
cursor:pointer;
}
.vmenu > li > ul.vmenu > a:focus~li {
top:0;
display:block;
cursor:pointer;
}
/* with CSS4 which is not yes supported by any browser
it has to be handled with javascript somehow
selects the li instead of a:focus to let the tab go through
.vmenu > li > ul.vmenu > $li > a:focus {
top:0;
display:block;
cursor:pointer;
}

具有完全嵌套的子菜单并部分支持键盘导航。参见:css 中的注释

示例 html:

<!DOCTYPE html>
<html>
    <head>
        <style>
* {
border-spacing:0px;
border:none;
height:inherit;
width:inherit;
margin:0px 0px 0px 0px;
padding:0px 0px 0px 0px;
background-repeat:no-repeat;
background-position:center;
}
body {
width:90%;
max-width:1600px;
min-width:800px;
margin:auto;
}
body > div {
width:100%;
}
.vmenu {
list-style:none;
height:75%;
min-height:24px;
width:16.67%;
max-width:544px;
min-width:90px;
text-align:center;
float:left;
z-index:1;
}
.vmenu > li {
width:100%;
list-style:none;
}
.vmenu > a {
background-color:#FFAF00;
width:100%;
height:100%;
display:block;
cursor:pointer;
}
.vmenu li > a {
background-color:#FF9F00;
display:block;
cursor:pointer;
}
.vmenu > li {
display:none;
}
.vmenu:hover > li {
display:block;
}
.vmenu > a:focus~li {
display:block;
}
/* with CSS4 which is not yes supported by any browser
it has to be handled with javascript somehow
selects the li instead of a:focus to let the tab go through
.vmenu > $li > a:focus {
display:block;
}
*/
.vmenu li > a:hover {
background-color: #2580FF;
color:#DDDDDD;
}
.vmenu li > a:focus {
background-color: #2580FF;
color:#DDDDDD;
}
.vmenu > a:hover {
background-color: #258072;
color:#DDDDDD;
}
.vmenu > a:focus {
background-color: #258072;
color:#DDDDDD;
}
.vmenu > li > ul.vmenu {
width:100%;
display:none;
}
.vmenu:hover > li > ul.vmenu {
display:block;
}
.vmenu > a:focus~li > ul.vmenu {
display:block;
}
.vmenu > li > ul.vmenu > li {
display:none;
padding:0px 0px 0px 100%;
}
.vmenu li ul.vmenu > a {
background-color:#FFAF0F;
float:left;
}
.vmenu li ul.vmenu:hover > a {
background-color:#258072;
color:#DDDDDD;
}
.vmenu li ul.vmenu > a:focus {
background-color:#258072;
color:#DDDDDD;
}
.vmenu > li > ul.vmenu:hover > li {
top:0;
display:block;
cursor:pointer;
}
.vmenu > li > ul.vmenu > a:focus~li {
top:0;
display:block;
cursor:pointer;
}
/* with CSS4 which is not yes supported by any browser
it has to be handled with javascript somehow
selects the li instead of a:focus to let the tab go through
.vmenu > li > ul.vmenu > $li > a:focus {
top:0;
display:block;
cursor:pointer;
}
*/
        </style>
    </head>
    <body>
        <div>
            <ul class="vmenu"><a href="">Menu1</a>
                <li><a href="">Item1</a></li>
                <li><a href="">Item2</a></li>
                <li><a href="">Item3</a></li>
                <li><a href="">Item4</a></li>
                <li><a href="">Item5</a></li>
                <li>
                    <ul class="vmenu"><a href="">SubMenu1</a>
                        <li><a href="">Item1</a></li>
                        <li><a href="">Item2</a></li>
                        <li><a href="">Item3</a></li>
                        <li><a href="">Item4</a></li>
                        <li><a href="">Item5</a></li>
                    </ul>
                </li>
                <li>
                    <ul class="vmenu"><a href="">SubMenu2</a>
                        <li><a href="">Item1</a></li>
                        <li><a href="">Item2</a></li>
                        <li><a href="">Item3</a></li>
                        <li><a href="">Item4</a></li>
                        <li><a href="">Item5</a></li>
                        <li>
                            <ul class="vmenu"><a href="">SubMenu1</a>
                                <li><a href="">Item1</a></li>
                                <li><a href="">Item2</a></li>
                                <li><a href="">Item3</a></li>
                                <li><a href="">Item4</a></li>
                                <li><a href="">Item5</a></li>
                            </ul>
                        </li>
                    </ul>
                </li>
            </ul>
            <ul class="vmenu"><a href="">Menu2</a>
                <li><a href="">Item1</a></li>
                <li><a href="">Item2</a></li>
                <li><a href="">Item3</a></li>
                <li><a href="">Item4</a></li>
                <li><a href="">Item5</a></li>
                <li>
                    <ul class="vmenu"><a href="">SubMenu1</a>
                        <li><a href="">Item1</a></li>
                        <li><a href="">Item2</a></li>
                        <li><a href="">Item3</a></li>
                        <li><a href="">Item4</a></li>
                        <li><a href="">Item5</a></li>
                    </ul>
                </li>
                <li>
                    <ul class="vmenu"><a href="">SubMenu2</a>
                        <li><a href="">Item1</a></li>
                        <li><a href="">Item2</a></li>
                        <li><a href="">Item3</a></li>
                        <li><a href="">Item4</a></li>
                        <li><a href="">Item5</a></li>
                    </ul>
                </li>
            </ul>
        </div>
    </body>
</html>

...它需要您在 z-index 和颜色方面进行一些工作,以使其看起来更好。

于 2012-10-24T05:37:11.247 回答
1

下拉导航演示

嗨,如果您在css

做这个

像这样

HTML 代码

<ul id="navi">
    <li><a href="" class="active">LInk 1</a></li>
    <li><a href="">LInk 2</a>
        <ul class="subnavi">
            <li><a href="">LInk 1</a></li>
            <li><a href="">LInk 1</a></li>
            <li><a href="">LInk 1</a></li>
            <li><a href="">LInk 1</a></li>
            <li><a href="">LInk 1</a></li>    
        </ul>

    </li>
    <li><a href="">LInk 3</a></li>

    <div class="cl"></div>
</ul>

CSS代码

.cl{clear:both;}
#navi{
    background:#0082c8;
    position:relative;
    margin-top:15px;
}


#navi > li{
    float:left;
    margin:0 10px;
    position:relative;
    padding:14px 0;
}

#navi li a, .subnavi li a{
    color:white;
    text-decoration:none;
    display:inline-block;
    line-height:29px;
    padding:0 13px;
    font-size:16px;
    font-family:arial;
    text-shadow: 0px 2px 2px #034e9f;
    filter: dropshadow(color=#034e9f, offx=0, offy=2);
}

#navi > li:hover > a, li:hover > a , #navi li a.active{
    background:#055c9f;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
    -webkit-box-shadow: inset 0px 3px 3px 0px #042960;
    -moz-box-shadow: inset 0px 3px 3px 0px #042960;
    box-shadow: inset 0px 3px 3px 0px #042960;
    border:1px solid #009ada;
    color:#f7cf00;
    line-height:27px;
    padding:0 12px;               
}

.subnavi{
    position:absolute;
    display:none;
    top:51px;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
    -webkit-box-shadow: 0px 0px 3px 1px #979395;
    -moz-box-shadow: 0px 0px 3px 1px #979395;
    box-shadow: 0px 0px 3px 1px #979395;
    background:#0082c8;
    border:1px solid #005890;
    padding:10px 0;
    white-space:nowrap;
}

#navi li:hover .subnavi{
    display:block;

}
#navi .subnavi li{
    margin:0;
}
#navi .subnavi li a{
    display:block;
    font-size:13px;
    padding:0 15px;
    border-radius:0;
    line-height:27px;
}
#navi .subnavi li a:hover{
    padding:0 15px;
    border-radius:0;
    border-left:0;
    border-right:0;
    line-height:25px;
}

[现场演示][2]**

于 2012-10-24T05:41:17.790 回答