2017-09-21 24 views
0

ちょうどブートストラップV4に移行します。スターターテンプレートをカスタマイズイム:https://v4-alpha.getbootstrap.com/examples/starter-template/ビューポートのサイズが変更されたときのナビゲーションバーの色の変更ブートストラップv4

私はnavbarは透明ではなくviewportsmxsときに暗いへ変更したいです。

Imはブレークポイントを使用して、それを変更しようと「ナビゲーションバー - 」カスタムクラスを追加することが、私はあなたがあなたの<nav>にブートストラップの.bg-darkクラスを使用している

html { 
 
    overflow: hidden; 
 
    height: 100%; 
 
    
 
} 
 

 

 

 
body { 
 
    padding-top: 5rem; 
 
    overflow: auto; 
 
    height: 100%; 
 

 
    background: linear-gradient(-45deg, #E8D1E2, #7CC4FF, #FFECBD, #BF9BFA); 
 
    \t background-size: 400% 400%; 
 
    \t -webkit-animation: Gradient 15s ease infinite; 
 
    \t -moz-animation: Gradient 15s ease infinite; 
 
    \t 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 { 
 
\t border-top: 2px solid #C66FF4; 
 
\t 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> 
 
\t <meta charset="utf-8"> 
 
\t <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
 
\t <meta name="viewport" content="width=device-width, initial-scale=1 shrink-to-fit=no"> 
 
\t <meta name="description" content="Full-Stack Graphic Designer, Illustrator, Front-End Development"> 
 
\t <meta name="author" content="Liliana Orozco"> 
 
\t <meta name="keywords" content="Designer, Creativity, Design, CSS, HTML5, Branding, Logotype, Illustration, Web, Advertising"> 
 
\t <title>Randomood says: Welcome!</title> 
 

 
\t <!-- Bootstrap 4.0 cdn --> 
 
\t <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous"> 
 

 

 
\t <!--custom styles for this page --> 
 
\t <link href="css/home.css" rel="stylesheet"> 
 

 

 
</head> 
 
<body> 
 
\t 
 

 
\t <!--navigation--> 
 
    <nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top navbar-custom"> 
 

 
    
 
    
 

 
    
 
    <!--Brand in navigation menu--> \t \t 
 
     
 
     <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 --> 
 

 

 

 

 

 
\t <!--JS, Popper and JQuery--> 
 
\t <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script> 
 
\t <script>window.jQuery || document.write('<script src="jquery-slim.min.js"><\/script>')</script> 
 
\t <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> 
 
\t <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script> 
 
</body>

答えて

0

は変更されません。 。このクラスのCSS宣言は次のとおりです。だから、

.bg-dark { 
    background-color: #343a40!important; 
} 

、あなたは背景色のプロパティをオーバーライドすることはできません。特定のスクリーンブレークポイントで背景色のプロパティを変更するには、.bg-darkクラスをJavascriptまたはJqueryで削除し、background-colorプロパティを変更するカスタムクラスを<nav>に変更します。私の説明があなたには分かりやすいことを願っています。

+0

私はあなたのコードをテストしました。 ".bg-dark"を削除すると、ナビゲーションが透明になります。それはあなたが望むものです、そうですか? –

+0

CSS3とhtmlだけを使って他の方法がありますか? /はい私はmdと画面サイズのデバイスで透明になりたいです。そしてxsデバイスでは、それをbg-darkに変更したいと思います。 –

+0

解決済み!ブレークポイントと.navbar {background-color}を使って変更しました。 –

0

あなたのブートストラップのテーマオーバーライドでSCSSで簡単:

.bg-dark { 
    background-color: #343a40; 
    @include media-breakpoint-up(sm) { 
     background-color: transparent; 
    } 
} 
関連する問題