简体   繁体   English

更改bootstrap导航栏右侧项目选择的颜色

[英]Change bootstrap nav-bar right items selected color

I'm using bootstrap for my project and I done some mofigication with my own CSS file. 我正在为我的项目使用bootstrap,我用自己的CSS文件做了一些mofigication。 however I need to change bootstrap nav-bar right side items selected color. 但是我需要更改bootstrap导航栏右侧项目选择的颜色。 No matter how hard I tried it want change with my CSS file 无论我怎么努力,都希望用我的CSS文件进行更改

 .navbar-static-top{ background-color: #3498db; } .navbar-brand { font-family: 'Lato', sans-serif; color:white; font-size: 190%; } body { font-size: 9px; } table-hover{ background-color: #FFF; } thead th { color: #FFF; text-align: Left; background-color: #3498db; font-size: 11px; } tbody td { height: 20px; padding: px px; font-size: 11px; text-align: right; } .vertical-center { background-color: #FFF; } .input-sm { font-size: 12px; color: black; } input[readonly] { background-color: #fff; /* any other styles */ } .nav li{ padding-right:10px; font-size: 120%; color: #FFF; } .nav.navbar-nav.navbar-right li a { color: #FFF; font-size: 120%; } .input-sm { height: 25px; padding: px px; font-size: 12px; } #submitbtn{ align: center; } input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; -moz-appearance: none; appearance: none; margin: 0; } input[type=number] { -moz-appearance:textfield; } 
 <nav class="navbar navbar-default navbar-static-top"> <div class="container-fluid"> <div class="navbar-header"> <a class="navbar-brand" href="#">Leave Application</a> <ul class="nav navbar-nav"> </ul> </div> <div class="collapse navbar-collapse"> <ul class="nav navbar-nav"> </ul> <ul class="nav navbar-nav navbar-right"> <li ><a href="sessionstart.php">My Leaves</a></li> <li class="active"><a href="request.php">Application</a></li> </ul> </div> </nav> 

and this is sample image how my site currently appeared in browser Link 这是我的网站当前在浏览器链接中出现的示例图像

I want change this gray color to white color with black text for selected item. 我希望将此灰色更改为白色,并为所选项目添加黑色文本。 how can I do this ? 我怎样才能做到这一点 ?

May be the problem here with the linking your external css file and bootstrap file 这可能是链接你的外部css文件和bootstrap文件的问题

you need place to them like this 你需要这样的地方

so that browser read the last css update from the file. 以便浏览器从文件中读取最后一次css更新。

now, try this. 现在,试试吧。 just add below code to your CSS. 只需在CSS中添加以下代码即可。

.navbar-default .navbar-nav > .active > a {
    background: #000000;
    color: white;
}

As you provided the code it is working on codepen. 当您提供代码时,它正在使用codepen。

I think, the problem is css file not linked in HTML page. 我认为,问题是在HTML页面中没有链接的css文件。

Please try this: 请试试这个:

nav.navbar .navbar-collapse ul.navbar-right li.active a {
  color: #000;
  background: #fff;
}

First of all make sure you are loading your custom css after bootstrap, otherwise it wont override it. 首先确保你在bootstrap之后加载你的自定义css,否则它不会覆盖它。

Secondly make sure that your css rules points to DOM element exactly the same or more specific then bootstrap does. 其次要确保你的css规则指向DOM元素与bootstrap完全相同或更具体。

Personally I prefix parent node with my own id or class and refer to it in my css. 我个人在父节点前面加上我自己的id或类,并在我的css中引用它。 This guarantees me that I always use more specific css declarations then bootstrap does. 这保证了我总是使用更具体的css声明然后bootstrap。

But if it doesn't makes sense to you you can simply use !important after your css proporty, but I recommend avoiding it at all costs unless you exactly know that there is no other way 但如果它对你没有意义,你可以简单地使用!在你的css比例之后重要,但我建议不惜一切代价避免它,除非你确切地知道没有别的办法

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

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