如何使此菜单下拉项显示垂直?

时间:2014-07-14 14:55:42

标签: css drop-down-menu navigation navbar

我制作了这个水平菜单,一切都很好,直到我意识到我不能让子菜单显得垂直,​​有人可以帮助我吗?

这是菜单代码:

<div id="nav_custom">
    <div id="nav_custom_wrapper"></div>
        <ul>
            <li><a href="#">NEW ARRIVALS</a>

            </li>
            <li>
            <a href="#">SEQUIN DRESSES</a>
                <ul id="nav_custom_sub">
                    <li><a href="#">AVAILABLE</a></li>
                    <li><a href="#">EXAMPLES SOLD</a></li>
                </ul>
            </li><li>
            <a href="#">BOHO DRESSES</a>
                <ul id="nav_custom_sub">
                    <li><a href="#">AVAILABLE</a></li>
                    <li><a href="#">EXAMPLES SOLD</a></li>
                </ul>   
            </li><li>
            <a href="#">MOD DRESSES</a>
                <ul id="nav_custom_sub">
                    <li><a href="#">AVAILABLE</a></li>
                    <li><a href="#">EXAMPLES SOLD</a></li>
                </ul>
            </li><li>
            <a href="#">PSYCHEDELIC DRESSES</a>
                <ul id="nav_custom_sub">
                    <li><a href="#">AVAILABLE</a></li>
                    <li><a href="#">EXAMPLES SOLD</a></li>
                </ul>
            </li><li>
            <a href="#">COATS & JACKETS</a>
                <ul id="nav_custom_sub">
                    <li><a href="#">AVAILABLE</a></li>
                    <li><a href="#">EXAMPLES SOLD</a></li>
                </ul>
            <li>
            <a href="#">KIMONOS</a>
                <ul id="nav_custom_sub">
                    <li><a href="#">AVAILABLE</a></li>
                    <li><a href="#">EXAMPLES SOLD</a></li>
                </ul>
            </li>
        </ul>
</div>

这是我用过的CSS:

#nav_custom {
text-decoration: none;
font-family: 'Source Sans Pro', sans-serif;
font-size: 14px;
font-style: normal;
font-variant: normal;
font-weight: 400;
line-height: 49px;
color: #000;
display: block;
padding: 10px;
width: 960px;
margin-left: -35px;
margin-right: auto;
text-align: center;
width: auto;
}
#nav_custom_wrapper {
width: 960px;
margin-left: auto;
margin-right: auto;
text-align: center;
}
#nav_custom ul{
list-style-type: none;
padding: 0;
margin: 0;
position: relative;
}
#nav_custom ul li{
display: inline-block;

}
#nav_custom ul li:hover{
color: #000;
text-decoration: none;
}
#nav_custom ul li a,visited{
color: #BA7145;
padding: 15px;
text-decoration: none;
}
#nav_custom ul li a:hover{
color: #000;
text-decoration: none;
}
#nav_custom ul li:hover ul{
display: block;
}
#nav_custom ul ul{
display: none;
position: absolute;
margin-top: -25px;
margin-left: -50px;
text-align: center;
color: #4f4f4f;
}

1 个答案:

答案 0 :(得分:0)

删除inline-block

上的#nav_custom ul li

请参阅工具示例小提琴:http://jsfiddle.net/Tv77g/

内联块的工作方式类似于浮点数,这就是为什么它们从左到右堆叠而不是彼此叠加的原因。

我没有去调整你的孩子。我不知道菜单应该如何显示。孩子们(#nav_custom ul ul)很可能会调整边距。您可以删除text-align:center;上的#nav_custom以使菜单完全左对齐。

要仅对儿童进行设置,请添加

#nav_custom_sub li { display: block !important; }

这将仅覆盖子项的内联块(在下拉列表中)。您必须调整边距才能使它们正确显示。