简体   繁体   English

Bootstrap导航栏背景颜色不变

[英]Bootstrap navbar background color not changing

I am using the bootstrap navbar for my website. 我正在为我的网站使用引导导航栏。 If I want to change the background color of the navbar I can do it using: 如果要更改导航栏的背景颜色,可以使用以下方法进行操作:

<!-- Navbar -->
<nav class="navbar navbar-default" role="navigation" >

    <div class="container-fluid" style="background-color:#000000">

       <p>hi</p>

    </div>

</nav>

But if I try to use css in an external sheet using either 但是,如果我尝试使用其中一个在外部工作表中使用CSS

.nav_backcolor {
   background-color:#000000;
}

or overiding the bootstrap classes in my stylesheet using 或使用以下样式覆盖我的样式表中的引导程序类

.navbar-default {

background-color:#000000;

}

and adding the class like 并添加类

<!-- Navbar -->
<nav class="navbar navbar-default nav_backcolor" role="navigation" >

<div class="container-fluid">

   <p>hi</p>

</div>

</nav>

it doesn't work. 它不起作用。 Any help please? 有什么帮助吗?

I believe Bootstrap uses the background image for linear-gradient which was causing an issue, try just setting only the main background attribute: 我相信Bootstrap将背景图片用于linear-gradient ,这会导致问题,请尝试仅设置主背景属性:

.navbar-default {
  background: #000000;
}

Try adding "!important" when adding the class to your CSS like this 像这样将类添加到CSS时,尝试添加“!important”

.navbar-default {
    background: #000 !important;
}

As the comments say, the html and css itself is fine. 正如评论所说,html和css本身很好。

The page you linked can't find your style sheet file. 您链接的页面找不到样式表文件。 Fix the url to your css file and you should be fine. 将网址固定到您的css文件,就可以了。

UPDATE: Seeing that it still has problems you can remove the Bootstrap theme to make it easier for yourself. 更新:看到它仍然有问题,您可以删除Bootstrap主题以使其更容易使用。 If you're gonna do a lot of styling you might be better off removing the theme entirely so that you don't have to override it for every small change. 如果您要进行很多样式设置,最好完全删除主题,这样就不必每次更改都覆盖它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM