Bootstrap 3更改导航栏按钮高度

时间:2014-08-20 09:33:56

标签: html twitter-bootstrap navbar graphical-logo

我将导航栏min-height40更改为55以使用徽标。

.navbar{
    position:relative;
    min-height:55px
}

我想知道如何更改navbar按钮的高度:

<div class="navbar navbar-default navbar-fixed-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">Navigation ein-/ausblenden</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="http://holdirbootstrap.de/examples/navbar-fixed-top/#"> <img src="images/logoverysmall.png">Company</a>       
    </div
    <div class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
        <li class="active"><a href="dev.htm">Home</a></li>
        <li><a href="http://holdirbootstrap.de/examples/navbar-fixed-top/#ueber">Über uns</a></li>
        <li><a href="http://holdirbootstrap.de/examples/navbar-fixed-top/#kontakt">Product</a></li>

        <li class="dropdown">
        <a href="#" data-toggle="dropdown" class="dropdown-toggle">0<b class="caret"></b></a>
        <ul class="dropdown-menu">
            <li><a href="#">1</a></li>
            <li><a href="#">2</a></li>
            <li><a href="#">3</a></li>
        </ul>
      </li>
      <li><a href="/kontakt">Kontakt</a></li>
      </ul>
    </div><!--/.nav-collapse -->
  </div>
  </div>
 </div>

2 个答案:

答案 0 :(得分:0)

通常,在bootstrap中,他们已经设置了导航栏高度。因此,如果要修改高度,请使用以下代码

  .navbar
   {
      position:relative;
      height:55px !important;
   }

在为特定导航栏编写样式的地方,为所有元素添加“!important”,因为在运行时它只需要运行时css。所以使用'!important'这个词。

答案 1 :(得分:0)

这里是完整的工作代码,如果你想改变test1或test2 css中的高度变化。

  <!DOCTYPE html>
  <html lang="en">
  <head>
  <meta charset="UTF-8">
  <title>Example of Twitter Bootstrap 3 Static Navbar</title>
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">       </script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"> </script>
  <style type="text/css">
.bs-example{
    margin: 20px;
}
.test1
{
    height:20px !important; 
    min-height:40px !important;
}
.test2
{
    height:20px !important; 
    padding-top:10px !important; 
    min-height:20px !important;
}
</style>
</head> 
<body>
<div class="bs-example">
<nav role="navigation" class="navbar navbar-inverse test1">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header test1">
        <button type="button" data-target="#navbarCollapse" data-toggle="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>
        <a href="#" class="navbar-brand test2">Brand</a>
    </div>
    <!-- Collection of nav links and other content for toggling -->
    <div id="navbarCollapse" class="collapse navbar-collapse test1">
        <ul class="nav navbar-nav">
            <li class="active test1"><a href="#" class="test2">Home</a></li>
            <li class="test1"><a href="#" class="test2">Profile</a></li>
            <li class="test1"><a href="#" class="test2">Messages</a></li>
        </ul>
        <ul class="nav navbar-nav navbar-right">
            <li><a href="#" class="test2">Login</a></li>
        </ul>
    </div>
</nav>
</div>
</body>
</html>