【问题标题】:How can I make this menus dropdown items show vertical?如何使此菜单下拉项显示垂直?
【发布时间】:2014-07-14 14:55:41
【问题描述】:

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

这里是菜单代码:

<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;
}

【问题讨论】:

    标签: css drop-down-menu navigation navbar


    【解决方案1】:

    删除#nav_custom ul li上的inline-block

    查看小提琴的工作示例:http://jsfiddle.net/Tv77g/

    Inline-block 的工作方式类似于浮动,这就是为什么它们从左到右并排堆叠,而不是一个在彼此之上。

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

    要仅对孩子设置此项,请添加

    #nav_custom_sub li { display: block !important; }

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

    【讨论】:

    • 我也这样做了,问题是我不希望菜单是垂直的,只有它的子菜单/子菜单,通过这样做,一切都变得垂直
    • #nav_custom_sub li { display: block !important;} 这样做将覆盖#nav_custom_sub 的列表项的内联块元素。您仍然需要调整 #nav_custom ul ul 的边距。 (小提琴已更新)。
    猜你喜欢
    • 2020-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    • 2018-02-02
    • 2023-03-26
    • 2018-08-16
    相关资源
    最近更新 更多