我正在修改bootstrap 3导航栏,某些CSS属性不适用...
我有这个导航栏HTML:
<nav class="navbar navbar-default">
<div id="navbar-principal" class="container-fluid">
<div id="navbar-colapsado" class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a id="logo" class="navbar-brand" (click)="onClick('Inicio')" [class.active]="'Inicio'===itemSelected" [routerLink]="['/']"><img src="app/img/logo.jpg" alt="Logo"></a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a [routerLink]="['/link']">Inicio</a></li>
<li role="button" class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Info<span class="caret">
</span></a>
<ul class="dropdown-menu">
<li><a [routerLink]="['/linkA']">Mis Compras</a></li>
<li><a [routerLink]="['/linkB']">Mis Facturas</a></li>
<li><a [routerLink]="['/linkC']">Mi Cuenta</a></li>
</ul>
</li>
<li>Other links</li>
<li>Other links</li>
<li>Other links</li>
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container-fluid -->
</nav>
我从CDN加载引导程序3,并使用以下CSS代码覆盖:
:host .nav.navbar-nav.navbar-right > li.dropdown.open,
.nav.navbar-nav.navbar-right > li.dropdown.open > a,
.nav.navbar-nav.navbar-right > li.dropdown.open > a:hover{
color: yellow;
background-color: rgba(61, 164, 65, 1);
border-color: #999999;
}
我的问题是当应用“颜色:黄色”时,“背景颜色”被完全忽略了。
我已经检查了chrome中的计算式CSS,似乎是正确的...但是有些东西超出了我的风格!
为了避免这种情况,我必须如何重写引导程序?
答案 0 :(得分:0)
只需在CSS中添加Parent类即可覆盖默认CSS。
在以下示例中,仅右导航栏被css覆盖。
.nav.navbar-nav.navbar-right > li.dropdown.open,
.nav.navbar-nav.navbar-right > li.dropdown.open > a,
.nav.navbar-nav.navbar-right > li.dropdown.open > a:hover{
color: yellow;
background: #3da441;
border-color: #999999;
}
<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>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<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>
<a class="navbar-brand" href="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
<li><a href="#">Link</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
答案 1 :(得分:0)
我终于找到了问题!
这是因为背景图像(包含在引导程序中)强加于背景颜色。
我已经修复了将此代码添加到组件css文件中的问题:
.navbar-default .navbar-nav > li > .dropdown-menu > li > a:hover,
.navbar-default .navbar-nav > li > .dropdown-menu > li > a:focus {
background-color: rgba(61, 164, 65, 0.1);
background-image: none;
}
.navbar-default .navbar-nav .open .dropdown-menu > .active > a,
.navbar-default .navbar-nav .open .dropdown-menu > .active > a:hover,
.navbar-default .navbar-nav .open .dropdown-menu > .active > a:focus {
background-color: rgba(61, 164, 65, 0.1);
background-image: none;
}
.navbar-default .navbar-nav > .active > a,
.navbar-default .navbar-nav > .active > a:hover,
.navbar-default .navbar-nav > .active > a:focus {
background-color: rgba(61, 164, 65, 0.1);
background-image: none;
}
.navbar-default .navbar-nav > .open > a,
.navbar-default .navbar-nav > .open > a:hover,
.navbar-default .navbar-nav > .open > a:focus {
background-color: rgba(61, 164, 65, 0.1);
background-image: none;