设置引导程序下拉菜单的宽度

时间:2015-10-08 00:59:27

标签: css twitter-bootstrap

我正在开发一个导航栏,它有一个使用bootstrap的下拉菜单。但是,我的下拉菜单占用的空间比实际单词本身As can been seen in inspect element in chrome

更多

我尝试在我的CSS中添加宽度:0%,但它没有工作。我创建了一个bootply链接http://www.bootply.com/bBYOCjV7GQ

1 个答案:

答案 0 :(得分:1)

您已将dropdown课程替换为class="drop down">,并且您的表单和navbar-right已嵌套在您的第一个ul内。

enter image description here

*由于您拥有如此多的链接/元素,一旦视口缩小,您仍然会看到导航栏中断和删除。



<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-default">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"> <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="#">LibSys</a>

    </div>
    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li class=""><a href="/books">List of Books</a>

        </li>
        <li class=""><a href="/checkouthistory">User CheckOut History</a>

        </li>
        <li class="dropdown"> <a class="dropdown-toggle" data-toggle="dropdown" href="#" style="min-width: 0px;">Book Suggestions<span class="caret"></span></a>

          <ul class="dropdown-menu" role="menu">
            <li class="active"><a href="/suggest">Suggest a Book</a>

            </li>
          </ul>
        </li>
      </ul>
      <form id="search-form" class="navbar-form navbar-left" action="/index_search" accept-charset="UTF-8" method="get">
        <input name="utf8" type="hidden" value="✓">
        <input type="text" name="search" id="search" class="form-control" placeholder="Search Books">
        <input type="submit" value="Search" class="btn btn-default">
      </form>
      <ul class="nav navbar-nav navbar-right">
        <li class="dropdown"> <a class="dropdown-toggle" data-toggle="dropdown" href="#">haris@email.com<span class="caret"></span></a>

          <ul class="dropdown-menu">
            <li class=""><a href="/users/9/edit">Edit Profile</a>

            </li>
          </ul>
        </li>
        <li><a rel="nofollow" data-method="delete" href="/logout">Log out</a>

        </li>
      </ul>
    </div>
  </div>
</nav>
&#13;
&#13;
&#13;