我正在尝试编辑引导程序导航栏的样式。但是,例如,我无法编辑颜色和删除边框。我想将颜色更改为白色,边框颜色更改为白色,我也包含下面的代码。谁能告诉我我做错了什么?
.navbar-default {
background-color: #ffffff;
border-color: #ffffff;
}
.navbar-default .navbar-brand {
color: #292929;
}
.navbar-default .navbar-brand:hover,
.navbar-default .navbar-brand:focus {
color: #ffd4d4;
}
.navbar-default .navbar-text {
color: #292929;
}
.navbar-default .navbar-nav > li > a {
color: #292929;
}
.navbar-default .navbar-nav > li > a:hover,
.navbar-default .navbar-nav > li > a:focus {
color: #ffd4d4;
}
.navbar-default .navbar-nav > .active > a,
.navbar-default .navbar-nav > .active > a:hover,
.navbar-default .navbar-nav > .active > a:focus {
color: #ffd4d4;
background-color: #ffffff;
}
.navbar-default .navbar-nav > .open > a,
.navbar-default .navbar-nav > .open > a:hover,
.navbar-default .navbar-nav > .open > a:focus {
color: #ffd4d4;
background-color: #ffffff;
}
.navbar-default .navbar-toggle {
border-color: #ffffff;
}
.navbar-default .navbar-toggle:hover,
.navbar-default .navbar-toggle:focus {
background-color: #ffffff;
}
.navbar-default .navbar-toggle .icon-bar {
background-color: #292929;
}
.navbar-default .navbar-collapse,
.navbar-default .navbar-form {
border-color: #292929;
}
.navbar-default .navbar-link {
color: #292929;
}
.navbar-default .navbar-link:hover {
color: #ffd4d4;
}
.navbar-brand {
transform: translateX(-50%);
left: 50%;
position: absolute;
}
.navbar-nav > li.navbar-left {
font-family: 'Nunito Sans', sans-serif;
font-size: 11px;
}
.navbar-brand {
padding: 0px;
}
.navbar-brand>img {
height: 90%;
width: auto;
}
.banner {
width: 100%;
/*background-color: #c3d7df;*/
}
.banner-inner {
max-width: 1100px;
margin: 0 auto;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device=width, initial-scale=1.0">
<title> My Website</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="style.css" />
<link href="https://fonts.googleapis.com/css?family=Nunito|Nunito+Sans|Playfair+Display" rel="stylesheet">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<header>
<div class="container">
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#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" href="http://jh.com"><img class= "logo" src="img/logo.png"></a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="navbar-left"><a href="index.html">TRAVEL</a></li>
<li class="navbar-left"><a href="#"> INSPIRATION</a></li>
<li class="navbar-left"><a href="#"> PORTFOLIO </a></li>
<li class="navbar-left"><a href="#"> ABOUT </a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li> <a href="https://www.instagram.com"><i class="fa fa-instagram"></i></a>
<li> <a href="https://www.pinterest.com"><i class="fa fa-pinterest"></i></a>
<li> <a href="https://www.facebook.com"><i class="fa fa-facebook"></i></a>
<li> <a href="https://twitter.com"><i class="fa fa-twitter"></i></a>
</ul>
</div>
<!--/.nav-collapse -->
</div>
<!--/.container-fluid -->
</nav>
</div>
</header>
<!---End Header-->
<section class="banner">
<div class="banner-inner">
<img class="banner" src="img/background.png">
</div>
</section>
<!---End Banner-->
</body>
</html>
答案 0 :(得分:2)
这种情况正在发生,因为您的css被默认的bootstrap css覆盖。
您只需要进行一次更改。在任何地方使用.navbar.navbar-default
代替.navbar-default
,这将使您的css优先于默认的css。
这是一篇关于css特异性的好文章:https://css-tricks.com/specifics-on-css-specificity/
.navbar.navbar-default {
background-color: #ffffff;
border-color: #ffffff;
}
.navbar.navbar-default .navbar-brand {
color: #292929;
}
.navbar.navbar-default .navbar-brand:hover,
.navbar.navbar-default .navbar-brand:focus {
color: #ffd4d4;
}
.navbar.navbar-default .navbar-text {
color: #292929;
}
.navbar.navbar-default .navbar-nav > li > a {
color: #292929;
}
.navbar.navbar-default .navbar-nav > li > a:hover,
.navbar.navbar-default .navbar-nav > li > a:focus {
color: #ffd4d4;
}
.navbar.navbar-default .navbar-nav > .active > a,
.navbar.navbar-default .navbar-nav > .active > a:hover,
.navbar.navbar-default .navbar-nav > .active > a:focus {
color: #ffd4d4;
background-color: #ffffff;
}
.navbar.navbar-default .navbar-nav > .open > a,
.navbar.navbar-default .navbar-nav > .open > a:hover,
.navbar.navbar-default .navbar-nav > .open > a:focus {
color: #ffd4d4;
background-color: #ffffff;
}
.navbar.navbar-default .navbar-toggle {
border-color: #ffffff;
}
.navbar.navbar-default .navbar-toggle:hover,
.navbar.navbar-default .navbar-toggle:focus {
background-color: #ffffff;
}
.navbar.navbar-default .navbar-toggle .icon-bar {
background-color: #292929;
}
.navbar.navbar-default .navbar-collapse,
.navbar.navbar-default .navbar-form {
border:none;
}
.navbar.navbar-default .navbar-link {
color: #292929;
}
.navbar.navbar-default .navbar-link:hover {
color: #ffd4d4;
}
.navbar-brand {
transform: translateX(-50%);
left: 50%;
position: absolute;
}
.nav.navbar-nav > li.navbar-left {
font-family: 'Nunito Sans', sans-serif;
font-size: 11px;
}
.navbar-brand {
padding: 0px;
}
.navbar-brand>img {
height: 90%;
width: auto;
}
.banner {
width: 100%;
/*background-color: #c3d7df;*/
}
.banner-inner {
max-width: 1100px;
margin: 0 auto;
}
@media (min-width:768px) and (max-width:991px){
.container.navbar-container {
width:100%;
padding:0;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device=width, initial-scale=1.0">
<title> My Website</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="style.css" />
<link href="https://fonts.googleapis.com/css?family=Nunito|Nunito+Sans|Playfair+Display" rel="stylesheet">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</head>
<body>
<header>
<div class="container navbar-container">
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#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" href="http://jh.com"><img class= "logo" src="http://images.financialexpress.com/2015/12/Lead-image.jpg"></a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="navbar-left"><a href="index.html">TRAVEL</a></li>
<li class="navbar-left"><a href="#"> INSPIRATION</a></li>
<li class="navbar-left"><a href="#"> PORTFOLIO </a></li>
<li class="navbar-left"><a href="#"> ABOUT </a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li> <a href="https://www.instagram.com"><i class="fa fa-instagram"></i></a>
<li> <a href="https://www.pinterest.com"><i class="fa fa-pinterest"></i></a>
<li> <a href="https://www.facebook.com"><i class="fa fa-facebook"></i></a>
<li> <a href="https://twitter.com"><i class="fa fa-twitter"></i></a>
</ul>
</div>
<!--/.nav-collapse -->
</div>
<!--/.container-fluid -->
</nav>
</div>
</header>
<!---End Header-->
<section class="banner">
<div class="banner-inner">
<img class="banner" src="img/background.png">
</div>
</section>
<!---End Banner-->
</body>
</html>
答案 1 :(得分:0)
检查此Bootstrap Navbar Generator
http://bootstrap3-menu.codedorigin.com/
http://seegatesite.com/bootstrap/bootstrap-navbar-online-generator.php