Bootstrap导航 - 菜单项之间的空间

时间:2018-01-08 17:50:04

标签: css html5 twitter-bootstrap

我设置了以下Bootstrap导航。我想在" Coverage"中减少ul中每个li之间的空间。下拉拨动。我用什么设置来做这件事?作为旁注,当我设置浮动:左边的ul li a,空间减少了,但我不需要漂浮来做这个。为什么它会缩小空间呢?

 <div>
<button class="btn btn-primary" [disabled]= false> Submit </button>
<button class="btn btn-primary" [disabled]= "false"> Submit </button>
</div>
编辑:我将我的ul更改为&#34; mynavlist&#34;,并添加了以下CSS:

    <nav class="navbar navbar-default navbar-fixed-top">
    <div class="container-fluid">
        <div class="navbar-header">
            <a class="navbar-brand  mycontent5" href="/?goHome=true"><span class="glyphicon glyphicon-home"></span></a>
            <button type="button" data-toggle="collapse" data-target=".navbar-collapse" class="navbar-toggle">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
        </div>
        <div class="collapse navbar-collapse navbar-left">
            <ul class="nav navbar-nav">
                <li><a href="/Analyst">Analysts</a></li>
                <li class="dropdown">
                    <a class="dropdown-toggle" data-toggle="dropdown" href="#">Coverage<span class="caret"></span></a>

                    <ul class="dropdown-menu" id="mynavlist">
                        <li><a href="/Coverage/Coverage?status=A">All Coverage</a></li>
                        <li><a href="/Coverage/CoverageAssignments?groupingBySector=True">Coverage Assignments</a></li>
                        <li><a href="/Holding/PortfolioCoverage">Portfolio Coverage</a></li>
                        <li><a href="/Holding/PortfolioSnapshot">Portfolio Snapshot</a></li>
                                <li><a href="/Writeup/WriteupSections?status=A">Writeup Sections</a></li>

                    </ul>
                </li>
                <li><a href="/Holding/List">Funds</a></li>
                <li><a href="/Blotter/Account?analystname=Scott%20Mabry">Intraday Orders</a></li>
                <li><a href="#" class="dropdown-toggle">Reports</a></li>
            </ul>
        </div>
</nav>

这导致以下结果:我想摆脱每个项目上方和下方的所有空白区域。增加px大小可以按预期更改我的列表,但是如何摆脱额外的空间呢?

ul

2 个答案:

答案 0 :(得分:2)

您必须减少每个项目的顶部和底部填充。请尝试以下css

.navbar-default .dropdown-menu>li>a {
  padding: 0 20px;
}


/*For responsive*/

@media (max-width: 767px) {
  .navbar-default .navbar-nav .open .dropdown-menu>li>a {
    padding: 0 20px;
  }
}

&#13;
&#13;
.navbar-default .dropdown-menu>li>a {
  padding: 0 20px;
}


/*For responsive*/

@media (max-width: 767px) {
  .navbar-default .navbar-nav .open .dropdown-menu>li>a {
    padding: 0 20px;
  }
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<nav class="navbar navbar-default navbar-fixed-top">
  <div class="container-fluid">
    <div class="navbar-header">
      <a class="navbar-brand  mycontent5" href="/?goHome=true"><span class="glyphicon glyphicon-home"></span></a>
      <button type="button" data-toggle="collapse" data-target=".navbar-collapse" class="navbar-toggle">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
    </div>
    <div class="collapse navbar-collapse navbar-left">
      <ul class="nav navbar-nav">
        <li><a href="/Analyst">Analysts</a></li>
        <li class="dropdown">
          <a class="dropdown-toggle" data-toggle="dropdown" href="#">Coverage<span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="/Coverage/Coverage?status=A">All Coverage</a></li>
            <li><a href="/Coverage/CoverageAssignments?groupingBySector=True">Coverage Assignments</a></li>
            <li><a href="/Holding/PortfolioCoverage">Portfolio Coverage</a></li>
            <li><a href="/Holding/PortfolioSnapshot">Portfolio Snapshot</a></li>
            <li><a href="/Writeup/WriteupSections?status=A">Writeup Sections</a></li>

          </ul>
        </li>
        <li><a href="/Holding/List">Funds</a></li>
        <li><a href="/Blotter/Account?analystname=Scott%20Mabry">Intraday Orders</a></li>
        <li><a href="#" class="dropdown-toggle">Reports</a></li>
      </ul>
    </div>
</nav>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

如果您使用浏览器控制台或检查器,则可以查看每个HTML元素以及应用于该元素的任何CSS。对于Bootstrap的Navbar组件,您将找到以下内容:

.navbar-nav > li > a {
  padding-top: 15px;
  padding-bottom: 15px;
}

15px更改为其他值将导致您所需的输出,但您应该注意Bootstrap根据某些媒体断点修改此元素的顶部和底部填充:您需要在此处对此进行说明定制