更改导航栏的颜色

时间:2016-10-17 17:08:26

标签: html css

如何让整个导航栏变黑?在这张图片http://prntscr.com/cvgvxj中,您可以看到有白色边框,我无法弄清楚如何移除它们/使它们变黑。

li:hover {
    background-color: white;
}
body {
    background-color: black;
}
.meniu {
    background-color: black;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Metal</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/stil.css">
    </head>
    <body>
        <script src="js/bootstrap.min.js" ></script>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
        <script src="J/js/collapse.js"></script>
        <script src="J/js/dropdown.js"></script>
        <script src="J/js/button.js"></script>
<nav class="meniu navbar navbar-default">
  <div class="container-fluid">

    <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>
    </div>


    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
     <ul class="nav navbar-nav">
        <li><a href="#">Link</a></li>
        <li><a href="#">Link</a></li>
        </ul> 
    </div>
  </div>
</nav>
    </body>
</html>

2 个答案:

答案 0 :(得分:0)

要更改导航栏本身的背景颜色,请将其添加到.nav类:

background-color:#002d60;

答案 1 :(得分:0)

实际上边框颜色是主要问题; see DEMO。我还评论了我改变的地方,看到了css部分。我为您建立了一个html结构作为建议的地方,所有css链接都在头标记.meniu { background: black !important; border-color:black !important; /*Set the main nav border color black..Don't Use !important in your custom.css file*/ border-radius:0 !important; /*By default it's 4px I change this coz on screen(>768px) It makes a border with 4px radius.. So the corners gets some white space..Don't Use !important in your custom.css file*/ } .navbar-default .navbar-collapse{ border-color:black !important; /*For Mobile Menu collapse background color black... Don't Use !important in your custom.css file*/ } .navbar-nav li:hover { background-color: white !important; /*Don't Use !important in your custom.css file*/ }内,并且在正文标记之前需要包含所有脚本标记。
[N.B:不要使用我在css中使用的!重要部分。我使用了!important很重要,因为我在同一页面覆盖bootstrap css以获取片段视图。阅读此When Using !important

<head>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
   
</head>
<body>
  <nav class="meniu navbar navbar-default">
   <div class="container-fluid">

    <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>
    </div>
   <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
     <ul class="nav navbar-nav">
        <li><a href="#">Link</a></li>
        <li><a href="#">Link</a></li>
        </ul> 
    </div>
  </div>
</nav>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

</body>
ID       year AB  H 2B 3B HR
JimBob01 2009 100 27 3 1 1
JimBob01 2010 154 37 6 2 5
JimBob01 2011 123 36 8 0 3