如何覆盖Bootstrap的类以增加导航栏高度?

时间:2016-12-20 21:49:58

标签: javascript jquery html css twitter-bootstrap

目前我的导航栏高约50px。我希望它大约是150px。我尝试通过在CSS文件中编写我自己的创建添加到Bootstrap的导航栏类,但更改导航栏,导航或其他任何内容的高度似乎不会影响布局。如何更改导航栏高度?还有,字体颜色?



.navbar-inverse {
	background-color: #337ab7;
	border-color:#337ab7;
	border-radius: 0px;
	height:100px;
	width:100%;
	position: fixed;
}

.navbar-inverse .navbar-nav>.open>a, .navbar-inverse .navbar-nav>.open>a:hover, .navbar-inverse .navbar-nav>.open>a:focus {
	color: #fff;
	background-color: #0e364c;
}

.navbar-inverse .navbar-nav>li>a {
	color:#ffffff;font-family: 
	'Open Sans', sans-serif;
}
.navbar-inverse .navbar-brand { 
	color:#ffffff;
}
.menu { 
	display:none;
}


@media all and (max-width:768px){

/*login register*/

@import url(http://fonts.googleapis.com/css?family=Roboto);

<head>
  {% load static %}
  <link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
  <link rel="stylesheet" href="https://opensource.keycdn.com/fontawesome/4.6.3/font-awesome.min.css"
  <link type = "text/css" rel = "stylesheet" href= "{% static 'polls/stylesheet.css' %}" />
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<nav class="navbar navbar-inverse" id ="bar">
  <div class="container-fluid">
    <div class="navbar-header">
      <a class="navbar-brand" href="#"><span class="glyphicon glyphicon-flag" aria-hidden="true"></span> The Transparency Project</a>
    </div><!--navbar-header close-->
    <div class="collapse navbar-collapse drop_menu" id="content_details">
      <ul class="nav navbar-nav">
        <li><a href="#"><span class="glyphicon glyphicon-home"></span> Home</a></li>  
        <li><a href="#"><span class="glyphicon glyphicon-search"></span>  Opinions and Analysis</a></li>
        <li><a href="#"><span class="glyphicon glyphicon-phone"></span> Contact</a></li>
      </ul><!--nav navbar-nav close-->
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#" data-toggle="modal" data-target="#signup-modal"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
        <li><a href="#" data-toggle="modal" data-target="#login-modal"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
      </ul><!--navbar-right close-->
    </div><!--collapse navbar-collapse drop_menu close-->
  </div><!--container-fluid close-->
</nav><!--navbar navbar-inverse close-->
<br>


<div class="container">
  <div class="jumbotron">
    <h1>sign up & login forms Tutorial</h1> 
    <p> click on login or sign up menu in header</p> 
  </div>
</div><!--container close-->
&#13;
&#13;
&#13;

4 个答案:

答案 0 :(得分:3)

您可以按照自己的方式进行编辑,只需确保在引导程序文件之后加载了css文件。不是之前,这就是它的样子。

这是基于假设这是你的css文件:

  <link type = "text/css" rel = "stylesheet" href= "{% static 'polls/stylesheet.css' %}" />

如果你交换这两个,它应该覆盖bootstraps设置:

  <link type = "text/css" rel = "stylesheet" href= "{% static 'polls/stylesheet.css' %}" />
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

答案 1 :(得分:3)

首先,您需要重新排列样式表。引导程序必须是第一个,并且您的自定义css文件必须在Bootstrap之后才能覆盖它。

这是正确的顺序:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link type = "text/css" rel = "stylesheet" href= "{% static 'polls/stylesheet.css' %}" />

现在,为了覆盖导航栏的高度,在自定义样式表中更改.navbar类的最小高度

.navbar {
    min-height: 150px;
}

并且对于颜色,您需要以下覆盖:

.navbar-inverse .navbar-nav > li > a {
    color: red; /* here goes the color of your choice */
}

答案 2 :(得分:0)

如果bootstrap覆盖了你的CSS属性,那么你必须为你定义的CSS属性指定!important ,比如

.navbar{
   height:150px !important;
}

答案 3 :(得分:0)

对于自定义高度,您必须使用!在定义身高时很重要。

.navbar {
   min-height: 150px !important;
}