我只是迁移到Bootstrap V4。我自定义了初学者模板:https://v4-alpha.getbootstrap.com/examples/starter-template/
我希望navbar
透明但在viewport
为sm
和xs
时变为黑暗。
我尝试使用断点更改它并添加'navbar-custom'类,但我没有更改
html {
overflow: hidden;
height: 100%;
}
body {
padding-top: 5rem;
overflow: auto;
height: 100%;
background: linear-gradient(-45deg, #E8D1E2, #7CC4FF, #FFECBD, #BF9BFA);
background-size: 400% 400%;
-webkit-animation: Gradient 15s ease infinite;
-moz-animation: Gradient 15s ease infinite;
animation: Gradient 15s ease infinite;
}
@-webkit-keyframes Gradient {
0% {
background-position: 0% 50%
}
50% {
background-position: 100% 50%
}
100% {
background-position: 0% 50%
}
}
@-moz-keyframes Gradient {
0% {
background-position: 0% 50%
}
50% {
background-position: 100% 50%
}
100% {
background-position: 0% 50%
}
}
@keyframes Gradient {
0% {
background-position: 0% 50%
}
50% {
background-position: 100% 50%
}
100% {
background-position: 0% 50%
}
}
.navbar {
border-top: 2px solid #C66FF4;
width: 100%
}
@media (min-width: 768px) {
nav .navbar .navbar-custom {
background: rgba(0,0,0,0);
}
}
.starter-template {
padding: 3rem 1.5rem;
text-align: center;
}
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1 shrink-to-fit=no">
<meta name="description" content="Full-Stack Graphic Designer, Illustrator, Front-End Development">
<meta name="author" content="Liliana Orozco">
<meta name="keywords" content="Designer, Creativity, Design, CSS, HTML5, Branding, Logotype, Illustration, Web, Advertising">
<title>Randomood says: Welcome!</title>
<!-- Bootstrap 4.0 cdn -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
<!--custom styles for this page -->
<link href="css/home.css" rel="stylesheet">
</head>
<body>
<!--navigation-->
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top navbar-custom">
<!--Brand in navigation menu-->
<a class="navbar-brand " href="#">Randomood</a>
<!--Brand image in navigation menu-->
<a class="navbar-brand" href="#"><img></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="#">Book</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</div>
</nav>
<div class="container">
<div class="starter-template">
<h1>Bootstrap starter template</h1>
<p class="lead">Use this document as a way to quickly start any new project.<br> All you get is this text and a mostly barebones HTML document.</p>
</div>
</div><!-- /.container -->
<!--JS, Popper and JQuery-->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script>window.jQuery || document.write('<script src="jquery-slim.min.js"><\/script>')</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>
</body>
答案 0 :(得分:0)
您正在.bg-dark
中使用Bootstrap的<nav>
课程。这个类的CSS声明是:
.bg-dark {
background-color: #343a40!important;
}
因此,您不能覆盖background-color属性。要在特定屏幕断点处更改background-color属性,请使用Javascript或Jquery删除.bg-dark
类,并添加更改background-color
<nav>
属性的自定义类。我希望你的解释清楚。
答案 1 :(得分:0)
在引导程序主题中使用scss轻松覆盖:
.bg-dark {
background-color: #343a40;
@include media-breakpoint-up(sm) {
background-color: transparent;
}
}