如何更改导航栏位置? CSS& HTML

时间:2016-06-03 21:28:57

标签: html css twitter-bootstrap navbar

我希望我能在这里向你们解释我所需要的一切:)

我想得到这样的一些: http://i.imgur.com/OzyQlHC.png

但是在我的代码中,我尝试了一些事情,但我无法做到这一点:我不知道这样做而且我找不到我想要的......

这是我的代码:

<body>


<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
  <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse-1">
    <span class="sr-only">Desplegar navegación</span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
  </button> 
</div>
<div class="navbar-center navbar-brand" href="#"><a class="navbar-brand">JVasconcelos</a></div>



<div class="collapse navbar-collapse" id="navbar-collapse-1">

  <form class="navbar-form navbar-left" role="search">
    <div class="form-group">
      <input class="form-control" placeholder="Search" type="text">
    </div>
    <button type="submit" class="btn btn-default"><i class="glyphicon glyphicon-search"></i></button>
  </form>
  <ul class="nav navbar-nav navbar-right">
    <li><a href="#">CV</a></li>
    <li><a href="#">Contacto</a></li>
</ul>
</div>    <!-- /.navbar-collapse -->
</nav>

<footer>

    <h3> &copy; 2016 - Jose Antonio - JVasconcelos </h3>

</footer>

<script src="js/jquery-2.2.4.min.js"></script>
<script src="js/bootstrap.min.js"></script>

</body>

这里是CSS:

.navbar-brand { float: none; }
.navbar-center { position: absolute; width: 100%; text-align: center; margin: auto; height:100%; }

- &GT;编辑:我用这个代码做了,但如果存在另一种更简单的方法呢?

.navbar { margin-top: 90px; margin-left: 450px; width: 900px; }

非常感谢你观看这篇文章和帮助,如果可以的话:)。

1 个答案:

答案 0 :(得分:2)

你不必使用任何技巧。

只需将代码放在divcontainer。将顶部和底部边距设置为body,就是这样。

HTML:

<div class="container">
  <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="#">Brand</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="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
          <li><a href="#">Link</a></li>
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
            <ul class="dropdown-menu">
              <li><a href="#">Action</a></li>
              <li><a href="#">Another action</a></li>
              <li><a href="#">Something else here</a></li>
              <li role="separator" class="divider"></li>
              <li><a href="#">Separated link</a></li>
              <li role="separator" class="divider"></li>
              <li><a href="#">One more separated link</a></li>
            </ul>
          </li>
        </ul>
        <form class="navbar-form navbar-left" role="search">
          <div class="form-group">
            <input type="text" class="form-control" placeholder="Search">
          </div>
          <button type="submit" class="btn btn-default">Submit</button>
        </form>
        <ul class="nav navbar-nav navbar-right">
          <li><a href="#">Link</a></li>
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
            <ul class="dropdown-menu">
              <li><a href="#">Action</a></li>
              <li><a href="#">Another action</a></li>
              <li><a href="#">Something else here</a></li>
              <li role="separator" class="divider"></li>
              <li><a href="#">Separated link</a></li>
            </ul>
          </li>
        </ul>
      </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
  </nav>
  <div class="content">Content</div>
  <footer>Footer</footer>
</div>

CSS:

body {
  margin-top: 100px;
  margin-bottom: 100px;
}
.navbar {
  margin-bottom: 0;
}
.content,
footer{
  height: 1000px;
  background: #333;
  color: #fff;
  font-size: 60px;
  text-align: center;
  padding-top: 400px
}
footer {
  height: 100px;
  background: #eee;
  color: #333;
  padding: 0;
}

CODEPEN EXAMPLE