编程语言
首页 > 编程语言> > javascript – Bootstrap 4下拉列表

javascript – Bootstrap 4下拉列表

作者:互联网

我想在导航栏中添加下拉列表.但它没有下降到它应该的位置:pic1

<link href="https://bootswatch.com/4/materia/bootstrap.min.css" rel="stylesheet"/>

   <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
   <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
   <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary nav-header">
      <a class="navbar-brand" href="#">TEST</a>
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarColor01" aria-controls="navbarColor01" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>

      <div class="collapse navbar-collapse" id="navbarColor01">
        <ul class="navbar-nav mr-auto">
            <li class="nav-item">
            <a class="nav-link" href="#">Home</a>
            </li>

            <li class="nav-item dropdown active">
                <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    Courses
                </a>
                <ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">

                </ul>
            </li>

            <li class="nav-item">
            <a class="nav-link" href="webinars">Webinars</a>
            </li>

            <li class="nav-item">
            <a class="nav-link" href="#">Library</a>
            </li>

            <li class="nav-item">
            <a class="nav-link" href="#">Instructins</a>
            </li>
        </ul>
        <ul class="proflie-dropdown navbar-nav">
            <li class="nav-item d-inline">
                <a class="btn btn-secondary dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    Username
                </a>
                <div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
                    <img class="float-left" src="img/users/kolyan.jpg" alt="">
                    <p>Username</p>
                    <br>
                    <br>
                    <p class="float-left">Name</p>
                    <p>Surname</p>
                    <p>Status</p>
                  <div class="dropdown-divider"></div>
                  <div class="btn-group" role="group" aria-label="Basic example">
                    <a class="btn btn-secondary" href="#">Open Profile</a>
                    <a class="btn btn-danger" href="#">Exit</a>
                  </div>
                </div>
                <!-- <div class="dropdown-menu dropdown-menu-right" x-placement="bottom-start" aria-labelledby="dropdownMenuLink" >

                </div> -->
            </li>
        </ul>
      </div>
    </nav>

它必须在按钮上对齐,因此它不会脱离页面.
this.

附:我是俄国人.对不起,如果我的英语不正确.如果是这样,请在评论中写下错误.

解决方法:

只需将btn-group类添加到您的个人资料下拉列表中,然后在下拉菜单中添加下拉菜单右键,如下所示:

<link href="https://bootswatch.com/4/materia/bootstrap.min.css" rel="stylesheet"/>

   <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
   <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
   <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary nav-header">
      <a class="navbar-brand" href="#">TEST</a>
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarColor01" aria-controls="navbarColor01" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>

      <div class="collapse navbar-collapse" id="navbarColor01">
        <ul class="navbar-nav mr-auto">
            <li class="nav-item">
            <a class="nav-link" href="#">Home</a>
            </li>

            <li class="nav-item dropdown active">
                <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    Courses
                </a>
                <ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">

                </ul>
            </li>

            <li class="nav-item">
            <a class="nav-link" href="webinars">Webinars</a>
            </li>

            <li class="nav-item">
            <a class="nav-link" href="#">Library</a>
            </li>

            <li class="nav-item">
            <a class="nav-link" href="#">Instructins</a>
            </li>
        </ul>
        <ul class="proflie-dropdown btn-group navbar-nav">
            <li class="nav-item d-inline">
                <a class="btn btn-secondary dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    Username
                </a>
                <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuLink">
                    <img class="float-left" src="img/users/kolyan.jpg" alt="">
                    <p>Username</p>
                    <br>
                    <br>
                    <p class="float-left">Name</p>
                    <p>Surname</p>
                    <p>Status</p>
                  <div class="dropdown-divider"></div>
                  <div class="btn-group" role="group" aria-label="Basic example">
                    <a class="btn btn-secondary" href="#">Open Profile</a>
                    <a class="btn btn-danger" href="#">Exit</a>
                  </div>
                </div>
                <!-- <div class="dropdown-menu dropdown-menu-right" x-placement="bottom-start" aria-labelledby="dropdownMenuLink" >

                </div> -->
            </li>
        </ul>
      </div>
    </nav>

标签:html,javascript,css,twitter-bootstrap,bootstrap-4
来源: https://codeday.me/bug/20190910/1798790.html