如何使我的下拉菜单在容器内部和左侧打开

时间:2018-10-08 11:26:32

标签: twitter-bootstrap

我想知道如何将ul.dropdown放在容器内和左侧。 我得到了第一个下拉菜单,可用于使用left:auto;覆盖的引导CSS。

第二个下拉列表与我的第一个下拉列表无法在同一位置开始。

请查看代码。 https://codepen.io/anon/pen/QZGrXx

<nav class="navbar navbar-default" role="navigation">     
        </div>
        <div class="container pd35">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="#">Brand</a>
            </div>
            <div class="collapse navbar-collapse" id="navbar-collapse-1">
                <ul class="nav navbar-nav navbar-left">
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown
                            <b class="caret"></b>
                        </a>
                        <ul class="dropdown-menu leftauto">
                            <a>First</a>
                            <li>
                                <a href="#">Action 1</a>
                            </li>
                            <li>
                                <a href="#">Another action</a>
                            </li>
                            <li>
                                <a href="#">Something else here</a>
                            </li>
                            <li>
                                <a href="#">Separated link</a>
                            </li>                  
                        </ul>
                    </li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown
                            <b class="caret"></b>
                        </a>
                        <ul class="dropdown-menu">
                            <li>
                                <a href="#"></a>
                            </li>
                            <li>
                                <a href="#"> action</a>
                            </li>
                            <li>
                                <a href="#"> else here</a>
                            </li>
                            <li>
                                <a href="#"> link</a>
                            </li>
                        </ul>
                    </li>
                </ul>
                <ul class="nav navbar-nav navbar-right">
                    <li>
                        <a href="#">Link</a>
                    </li>
                    <li>
                        <a href="#">Link</a>
                    </li>
                    <li>
                        <a href="#">Link</a>
                    </li>
                </ul>
            </div>
        </div>
        <!-- /.navbar-collapse -->
    </nav>






    .nav {
    margin-bottom: 0;
}

.nav>li.dropdown.open {
    position: static;
}

.nav>li.dropdown.open .dropdown-menu {
    border: none;
    box-shadow: none;
    border-top: 1px solid #eaeaea;
}

.dropdown-menu>li {
}

.nav.navbar-nav {
    float: right;
}

.navbar {
    margin-bottom: 0px;
    border-radius: 0;
    border-bottom: 1px solid #eaeaea;

}

.dropdown-menu>li {
}

.dropdown-menu>li>a {
    white-space: unset;
}

.navbar-brand {
    transform: translateX(-50%);
    left: 50%;
    position: absolute;
}

.dropdown-menu {
    background-color: blue;
}
.pd35 {
    padding: 35px 0px;
}
.leftauto { 
    left: auto !important;
}

上面的代码是为引导程序编写的导航UI。

2 个答案:

答案 0 :(得分:0)

使用垂直伸缩列

<div class="collapse navbar-collapse" id="navbar-collapse-1">
                <ul class="nav navbar-nav navbar-left">

成为

                <ul class="nav navbar-left flex-column">

答案 1 :(得分:0)

尝试

 <div class="collapse navbar-collapse" id="navbar-collapse-1">
                <ul class="nav navbar-nav navbar-left">
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown
                            <b class="caret"></b>
                        </a>
                        <ul class="dropdown-menu leftauto">
                            <a>First</a>
                            <li>
                                <a href="#">Action 1</a>
                            </li>
                            <li>
                                <a href="#">Another action</a>
                            </li>
                            <li>
                                <a href="#">Something else here</a>
                            </li>
                            <li>
                                <a href="#">Separated link</a>
                            </li>                  
                        </ul>
                    </li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown
                            <b class="caret"></b>
                        </a>
                        <ul class="dropdown-menu pull-left leftauto">
                            <li>
                                <a href="#"></a>
                            </li>
                            <li>
                                <a href="#"> action</a>
                            </li>
                            <li>
                                <a href="#"> else here</a>
                            </li>
                            <li>
                                <a href="#"> link</a>
                            </li>
                        </ul>
                    </li>
                </ul>
                <ul class="nav navbar-nav navbar-right">
                    <li>
                        <a href="#">Link</a>
                    </li>
                    <li>
                        <a href="#">Link</a>
                    </li>
                    <li>
                        <a href="#">Link</a>
                    </li>
                </ul>
            </div>

在第二个下拉菜单中。我猜想自动模式软件重叠了,这可以解决问题left: auto !important;