导航栏中的徽标,导航列表上方和徽标下方的间距

时间:2013-12-31 15:02:28

标签: html twitter-bootstrap space

我一直在尝试使用Bootstrap 3编写响应式标头,我只有一个。

导航列表上方还有一个空格,也位于徽标下方。 我如何排列他们两个? (标志&安培; NAV)

我的标题图片解释了问题:

the header problem

我的代码:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Bootstrap</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/custom4.css">
    <script src="js/respond.js"></script>
</head>
<body>
    <div class="row">
        <nav class="navbar navbar-default" role="navigation">

            <div class="navbar-header">
                <img src="img/logo.png" alt="logo" class="visible-xs">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#collapse">
                    <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="container"> 
                <div class="collapse navbar-collapse" id="collapse">

                    <img src="img/logo.png" alt="logo" class="hidden-xs push-left">
                        <ul class="nav navbar-nav pull-right">
                            <li><a href="#" class="active">Home</a></li>
                            <li><a href="#">pages</a></li>
                            <li><a href="#">Blog</a></li>
                            <li><a href="#">Portfilio</a></li>
                            <li><a href="#">Conact</a></li>
                        </ul>

                </div>
            </div>

        </nav>
    </div>
    <!-- Javasctipt --> 
    <script src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

从结构上来说,你的html与我的方法和导航栏实现的bootstrap上的文档不同。你把.row放在col- *类附近。如果图像相同,则无需复制小型和大型徽标。您也可以在最小宽度中修改品牌和定位。不知道您的徽标宽度,但您可以轻松调整所需的最小宽度,并且在最小宽度中,调整父级a上的填充,以便在视觉上与徽标一致。


DEMO:http://jsbin.com/aXAyicIS/1/

编辑:http://jsbin.com/aXAyicIS/1/edit


<强> CSS

.navbar-brand {
    width: 100%;
    padding: 0 70px 0 15px;
}
/* logo image on mobile */
.navbar-brand img {
    max-width: 100%
}
.navbar-toggle {
    position: absolute;
    float: none;
    right: 0;
    top: 5px;
}
@media (min-width:768px) { 
    .navbar-brand {
        float: none;
        width: auto;
        max-height: none;
        padding: 0!important;
    }
    .navbar-header {
        float: left;
        margin: 0;
        width: 30%;
    }
    /* logo image */
    .navbar-brand img {
        margin: 0;
        max-width: 100%;
        max-height: none;
    }
    .nav.navbar-nav li.active a,
    .nav.navbar-nav li.active a:hover {
        background: transparent
    }
    #nav-collapse {
        float: right;
        padding: 0!important;
        margin: 0!important;
        width: 70%;
    }
}

<强> HTML

<div class="navbar navbar-default navbar-static-top" role="navigation">
 <div class="container">
  <div class="navbar-header">
   <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
     <span class="sr-only">Toggle navigation</span>
     <span class="icon-bar"></span>
     <span class="icon-bar"></span>
     <span class="icon-bar"></span>
   </button>
   <a href="yourlink.html" class="navbar-brand"> <img src="http://placehold.it/300x80/444444/FFFFFF&text=LOGO"> </a>
  </div>
  <div id="nav-collapse" class="collapse navbar-collapse">
   <ul class="nav navbar-nav navbar-right">
    <li class="active"><a href="#testme1" class="anchor">Anchor 1</a></li>
    <li><a href="#testme2" class="anchor">Anchor 2</a></li>
    <li><a href="#testme3" class="anchor">Anchor 3</a></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="#">Test</a></li>
      <li><a href="#">Another link</a></li>
      <li><a href="#">Something else here</a></li>
      <li class="divider"></li>
      <li class="dropdown-header">Nav header</li>
      <li><a href="#">Separated link</a></li>
      <li><a href="#">One more separated link</a></li>
     </ul>
    </li>
   </ul>
  </div>
  <!--/.nav-collapse -->
 </div>
 <!--/.container -->
</div>
<!--.navbar-->