2

我正在创建一个 Twitter Bootstrap 主导航和子导航,主导航上有一个下拉菜单。问题是我永远无法让下拉菜单显示在子导航上方。这是HTML:

<div class="mainnav navbar navbar-fixed-top navbar-inverse">
    <div class="navbar-inner">
        <div class="container">
            <ul class="nav">
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                        Settings
                    </a>
                    <ul class="dropdown-menu">
                        <li><a>test 1</a></li>
                        <li><a>test 2</a></li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
</div>

<div class="subnav navbar navbar-fixed-top">
    <div class="navbar-inner">
        <div class="container">
            <ul class="nav">
                <li><a>foo</a></li>
                <li><a>bar</a></li>
            </ul>
        </div>
    </div>
</div>

CSS:

.subnav {
    top: 40px;
}

.mainnav .dropdown-menu {
    // how can I show this menu above the subnav???
}

​</p>

4

2 回答 2

2

没关系,这是我自己想出来的。

.subnav {
    top: 40px;
    z-index: 1020; // make z-index smaller than .mainnav
}

JsFiddle 链接:

http://jsfiddle.net/j2pCX/1/

于 2012-10-23T04:54:32.640 回答
1

试试 z-index:

.subnav {
    position: absolute;
    top: 40px;
    z-index: 10;

}

.mainnav .dropdown-menu {
    position: absolute;
    z-index: 20;
}
于 2012-10-23T04:57:52.720 回答