我想用不同颜色自定义导航栏,但我只能管理o成功更改背景颜色。每当我尝试更改其他属性时,它只会赢得工作 - 它只会使用默认的深灰色。
我的目标是使用:
https://jsfiddle.net/zfv61Lmu/7/
body {
height: 100%;
padding-top: 50px;
}
section {
height: calc(90% - 50px);
}
.nav .active {
background: #6dafad!important;
}
.navbar-inverse .navbar-nav li.active a {
background-color: #6dafad;
}
.affix {
padding: 0px;
-webkit-transition: padding 0.2s linear;
-moz-transition: padding 0.2s linear;
-o-transition: padding 0.2s linear;
transition: padding 0.2s linear;
}
.affix-top {
padding-top: 15px;
padding-bottom: 15px;
-webkit-transition: padding 0.5s linear;
-moz-transition: padding 0.5s linear;
-o-transition: padding 0.5s linear;
transition: padding 0.5s linear;
}
.navbar-brand {
padding: 0px;
margin: 0px;
max-height: 50px;
}

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div id="wrap">
<div class="navbar navbar-inverse navbar-fixed-top" style="background-color: #d1e6c5; color: #fff; border-color: transparent;">
<div class="container">
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav pull-right">
<li><span class="glyphicon glyphicon-globe"></span></li>
<li class="divider-vertical"></li>
<li><a href="#">PT</a></li>
<li class="divider-vertical"></li>
<li><a href="#">EN</a></li>
<li class="divider-vertical"></li>
<li><a href="#">FR</a></li>
<li class="divider-vertical"></li>
<li><a href="#">DE</a></li>
</ul>
</div>
</div>
</div>
<div class="navbar navbar-inverse navbar-light" style="background-color: #97CACA; color: #fff; border-color: transparent;" data-spy="affix" data-offset-top="100">
<div class="container">
<div 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 class="navbar-brand navbar-fixed-top" href="#"><img class="img-responsive logo" width="300" height="300" src="https://ibb.co/ejwDtS" alt=""></a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Sobre Nós</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Serviços <b class="caret"></b></a>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Bebés e Crianças</a></li>
<li><a href="#">Adultos e Séniores</a></li>
<li><a href="#">Empresas</a></li>
</ul>
</li>
<li><a href="#">Contactos</a></li>
</ul>
</div>
</div>
</div>
</div>
&#13;
另外,如何在第一个导航栏上将高度减半?它太厚了。我希望它更薄,因此它只会用来改变语言。 (另外,为什么字形对齐?)。
答案 0 :(得分:0)
我在顶部导航栏中添加了一个类:navbar-top。 我还使用了子选择器(&gt;)。 尽量避免在css中使用!important。
body {
height:100%;
padding-top:50px;
}
section {
height:calc(90% - 50px);
}
.affix {
padding:0px;
-webkit-transition:padding 0.2s linear;
-moz-transition:padding 0.2s linear;
-o-transition:padding 0.2s linear;
transition:padding 0.2s linear;
}
.affix-top {
padding-top:15px;
padding-bottom:15px;
-webkit-transition:padding 0.5s linear;
-moz-transition:padding 0.5s linear;
-o-transition:padding 0.5s linear;
transition:padding 0.5s linear;
}
.navbar.navbar-top {
background: #d1e6c5;
color: #fff;
border-color: transparent;
}
.navbar.navbar-top li a:link,
.navbar.navbar-top li a:visited {
color: #fff;
}
.navbar.navbar-inverse.navbar-light {
background-color: #97CACA;
color: #fff;
border-color: transparent;
}
.navbar-brand {
padding: 0px;
margin: 0px;
max-height: 50px;
}
.nav.navbar-nav.navbar-right > li.active > a {
background: #6dafad;
color: #d4e1e3;
}
.nav.navbar-nav.navbar-right a:hover {
color: #d4e1e3;
}
<!DOCTYPE html>
<html lang="pt">
<head>
<title>navbar</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<!--/ INICIO cabeçalho <-->
<div id="wrap">
<div class="navbar navbar-inverse navbar-fixed-top navbar-top">
<div class="container">
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav pull-right">
<li>
<span class="glyphicon glyphicon-globe"></span>
</li>
<li class="divider-vertical"></li>
<li><a href="#">PT</a></li>
<li class="divider-vertical"></li>
<li><a href="#">EN</a></li>
<li class="divider-vertical"></li>
<li><a href="#">FR</a></li>
<li class="divider-vertical"></li>
<li><a href="#">DE</a></li>
</ul>
</div>
</div>
</div>
<div class="navbar navbar-inverse navbar-light" data-spy="affix" data-offset-top="100">
<div class="container">
<div 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 class="navbar-brand navbar-fixed-top" href="#"><img class="img-responsive logo" width="300" height="300" src="img/logo.png" alt=""></a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Sobre Nós</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Serviços <b class="caret"></b></a>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Bebés e Crianças</a></li>
<li><a href="#">Adultos e Séniores</a></li>
<li><a href="#">Empresas</a></li>
</ul>
</li>
<li><a href="#">Contactos</a></li>
</ul>
</div>
</div>
</div>
</div>
<!--/ FIM cabeçalho <-->
</body>
</html>
答案 1 :(得分:0)
我编辑了另一篇文章。 试试这个:
我在顶部导航栏中添加了一个类:navbar-top。我还使用了子选择器(&gt;)。尽量避免在css中使用!important。
body {
height:100%;
padding-top:50px;
}
section {
height:calc(90% - 50px);
}
.affix {
padding:0px;
-webkit-transition:padding 0.2s linear;
-moz-transition:padding 0.2s linear;
-o-transition:padding 0.2s linear;
transition:padding 0.2s linear;
}
.affix-top {
padding-top:15px;
padding-bottom:15px;
-webkit-transition:padding 0.5s linear;
-moz-transition:padding 0.5s linear;
-o-transition:padding 0.5s linear;
transition:padding 0.5s linear;
}
.navbar.navbar-top {
background: #d1e6c5;
color: #fff;
border-color: transparent;
}
.navbar.navbar-top li a:link,
.navbar.navbar-top li a:visited {
color: #fff;
}
.navbar.navbar-inverse.navbar-light {
background-color: #97CACA;
color: #fff;
border-color: transparent;
}
.navbar-brand {
padding: 0px;
margin: 0px;
max-height: 50px;
}
.nav.navbar-nav.navbar-right > li.active > a {
background: #6dafad;
color: #d4e1e3;
}
.nav.navbar-nav.navbar-right a:hover {
color: #d4e1e3;
}
&#13;
<!DOCTYPE html>
<html lang="pt">
<head>
<title>navbar</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<!--/ INICIO cabeçalho <-->
<div id="wrap">
<div class="navbar navbar-inverse navbar-fixed-top navbar-top">
<div class="container">
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav pull-right">
<li>
<span class="glyphicon glyphicon-globe"></span>
</li>
<li class="divider-vertical"></li>
<li><a href="#">PT</a></li>
<li class="divider-vertical"></li>
<li><a href="#">EN</a></li>
<li class="divider-vertical"></li>
<li><a href="#">FR</a></li>
<li class="divider-vertical"></li>
<li><a href="#">DE</a></li>
</ul>
</div>
</div>
</div>
<div class="navbar navbar-inverse navbar-light" data-spy="affix" data-offset-top="100">
<div class="container">
<div 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 class="navbar-brand navbar-fixed-top" href="#"><img class="img-responsive logo" width="300" height="300" src="img/logo.png" alt=""></a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Sobre Nós</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Serviços <b class="caret"></b></a>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Bebés e Crianças</a></li>
<li><a href="#">Adultos e Séniores</a></li>
<li><a href="#">Empresas</a></li>
</ul>
</li>
<li><a href="#">Contactos</a></li>
</ul>
</div>
</div>
</div>
</div>
<!--/ FIM cabeçalho <-->
</body>
</html>
&#13;
答案 2 :(得分:0)
好的,所以我设法改变颜色:
.navbar-inverse .navbar-nav li.active a{
background-color: #6dafad;
color: #fff;
border-radius:
margin: 0 0.25em;
}
.navbar-inverse .navbar-nav > li > a {
color: #ffffff;
}
.navbar-inverse .navbar-nav > li > a:hover,
.navbar-inverse .navbar-nav > li > a:focus {
color: #d4e1e3;
}
.navbar-inverse .navbar-nav > .active > a,
.navbar-inverse .navbar-nav > .active > a:hover,
.navbar-inverse .navbar-nav > .active > a:focus {
color: #d4e1e3;
background-color: #6dafad;
}
.navbar-inverse .navbar-nav > .open > a,
.navbar-inverse .navbar-nav > .open > a:hover,
.navbar-inverse .navbar-nav > .open > a:focus {
color: #d4e1e3;
background-color: #6dafad;
}