2017-08-25 104 views
0

我打算讓我的bootstrap導航欄切換顯示內容而不是將其按下。我嘗試過不同的技巧,包括過去發佈的一些解決方案,但仍然無法完成。我發現大多數人都提出了navbar-fixed-top,這對我不起作用。如何讓我的bootstrap導航欄切換覆蓋內容?

.navbar { 
 
    -webkit-transition: all 0.6s ease-out; 
 
    -moz-transition: all 0.6s ease-out; 
 
    -o-transition: all 0.6s ease-out; 
 
    -ms-transition: all 0.6s ease-out; 
 
    transition: all 0.6s ease-out; 
 
    border-radius: 0px; 
 
} 
 

 
.navbar-brand { 
 
    width: 120px; 
 
    height: 120px; 
 
} 
 

 
.navbar-brand img { 
 
    width: 100px; 
 
    height: 100px; 
 
} 
 

 

 
/* LOGO ANIMATION */ 
 

 
@-webkit-keyframes rotate { 
 
    0%, 
 
    80% { 
 
    -webkit-transform: rotate(0deg); 
 
    } 
 
    90%, 
 
    100% { 
 
    -webkit-transform: rotate(360deg); 
 
    } 
 
} 
 

 
@keyframes rotate { 
 
    0%, 
 
    80% { 
 
    transform: rotate(0deg); 
 
    } 
 
    90%, 
 
    100% { 
 
    transform: rotate(360deg); 
 
    } 
 
} 
 

 
#logo { 
 
    -webkit-animation: rotate 5s infinite linear; 
 
    -moz-animation: rotate 5s infinite linear; 
 
    -o-animation: rotate 5s infinite linear; 
 
    -ms-animation: rotate 5s infinite linear; 
 
    animation: rotate 5s infinite linear; 
 
} 
 

 
.navbar-default { 
 
    background-color: rgba(0, 0, 0, 0); 
 
    border: none; 
 
} 
 

 
.navbar-right { 
 
    padding-top: 20px; 
 
} 
 

 
.navbar-default .navbar-nav>li>a { 
 
    color: #07d4de; 
 
} 
 

 
.navbar-default .navbar-nav>li>a:hover { 
 
    color: #fff; 
 
    background-color: #07d4de; 
 
} 
 

 
.navbar-default .navbar-nav>.active>a, 
 
.navbar-default .navbar-nav>.active>a:hover, 
 
.navbar-default .navbar-nav>.active>a:focus { 
 
    background-color: #07d4de; 
 
    color: white; 
 
} 
 

 
.navbar-default .navbar-toggle { 
 
    border-color: #07d4de; 
 
} 
 

 
.navbar-default .navbar-toggle:hover { 
 
    background-color: #07d4de; 
 
} 
 

 
.navbar-toggle { 
 
    margin-top: 30px; 
 
    height 
 
} 
 

 
.navbar-default .navbar-collapse, 
 
.navbar-default .navbar-form { 
 
    border-color: #07d4de; 
 
    text-align: center; 
 
} 
 

 
.navbar-default .navbar-toggle .icon-bar { 
 
    background-color: #07ded4; 
 
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> 
 
<section id="container"> 
 
    <nav class="navbar navbar-default"> 
 
    <div class="container"> 
 
     <div class="navbar-header"> 
 
     <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse-2"> 
 
          <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" id="logo" href="index.html"><img src="img/logo9.png" alt="Logo"></a> 
 
     </div> 
 
     <div class="collapse navbar-collapse" id="navbar-collapse-2"> 
 
     <ul class="nav navbar-nav navbar-right"> 
 
      <li class="active"><a href="#">Home</a></li> 
 
      <li><a href="about.html">About</a></li> 
 
      <li><a href="portfolio.html">Portfolio</a></li> 
 
      <li><a href="#">Blog</a></li> 
 
      <li><a href="contact.html">Contact</a></li> 
 
      <li><a href="#">Hire Me</a></li> 
 
     </ul> 
 
     </div> 
 
     <!-- /.navbar-collapse --> 
 
    </div> 
 
    <!-- /.container --> 
 
    </nav> 
 
    <!-- /.navbar --> 
 
    <div id="myname"> 
 
    <h1 class="quotes">I am <span style="color: #07d4de">Creative</span></h1> 
 
    <h1 class="quotes">I am <span style="color: #07d4de">Smart</span></h1> 
 
    <h1 class="quotes">I am <span style="color: #07d4de">Awesome</span></h1> 
 
    <h1 class="quotes">I am <span style="color: #07d4de">Olawale</span></h1> 
 
    </div> 
 
</section>

+0

爲什麼'Navbar的固​​定top'不適合你? – fen1x

+0

,因爲佈局不需要固定導航欄。即使在將navbar-fixed-top包含到課程中後,如果展開菜單按鈕,它仍然不起作用。 –

+0

所以你想讓導航欄不被固定在大屏幕上,並固定在小屏幕上? – fen1x

回答

0

我想你想這樣

.navbar { 
 
    -webkit-transition: all 0.6s ease-out; 
 
    -moz-transition: all 0.6s ease-out; 
 
    -o-transition: all 0.6s ease-out; 
 
    -ms-transition: all 0.6s ease-out; 
 
    transition: all 0.6s ease-out; 
 
    border-radius: 0px; 
 
} 
 

 
.navbar-brand { 
 
    width: 120px; 
 
    height: 120px; 
 
} 
 

 
.navbar-brand img { 
 
    width: 100px; 
 
    height: 100px; 
 
} 
 

 

 
/* LOGO ANIMATION */ 
 

 
@-webkit-keyframes rotate { 
 
    0%, 
 
    80% { 
 
    -webkit-transform: rotate(0deg); 
 
    } 
 
    90%, 
 
    100% { 
 
    -webkit-transform: rotate(360deg); 
 
    } 
 
} 
 

 
@keyframes rotate { 
 
    0%, 
 
    80% { 
 
    transform: rotate(0deg); 
 
    } 
 
    90%, 
 
    100% { 
 
    transform: rotate(360deg); 
 
    } 
 
} 
 

 
#logo { 
 
    -webkit-animation: rotate 5s infinite linear; 
 
    -moz-animation: rotate 5s infinite linear; 
 
    -o-animation: rotate 5s infinite linear; 
 
    -ms-animation: rotate 5s infinite linear; 
 
    animation: rotate 5s infinite linear; 
 
} 
 

 
.navbar-default { 
 
    background-color: rgba(0, 0, 0, 0); 
 
    border: none; 
 
} 
 

 
.navbar-right { 
 
    padding-top: 20px; 
 
} 
 

 
.navbar-default .navbar-nav>li>a { 
 
    color: #07d4de; 
 
} 
 

 
.navbar-default .navbar-nav>li>a:hover { 
 
    color: #fff; 
 
    background-color: #07d4de; 
 
} 
 

 
.navbar-default .navbar-nav>.active>a, 
 
.navbar-default .navbar-nav>.active>a:hover, 
 
.navbar-default .navbar-nav>.active>a:focus { 
 
    background-color: #07d4de; 
 
    color: white; 
 
} 
 

 
.navbar-default .navbar-toggle { 
 
    border-color: #07d4de; 
 
} 
 

 
.navbar-default .navbar-toggle:hover { 
 
    background-color: #07d4de; 
 
} 
 

 
.navbar-toggle { 
 
    margin-top: 30px; 
 
    height 
 
} 
 

 
.navbar-default .navbar-collapse, 
 
.navbar-default .navbar-form { 
 
    border-color: #07d4de; 
 
    text-align: center; 
 
} 
 

 
.navbar-default .navbar-toggle .icon-bar { 
 
    background-color: #07ded4; 
 
} 
 
@media screen and (max-width:767px){ 
 
.navbar .navbar-collapse { 
 
    background: #f8f8f8; 
 
    position: absolute; 
 
    width: 100%; 
 
} 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/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" /> 
 
<section id="container"> 
 
    <nav class="navbar navbar-default"> 
 
    <div class="container"> 
 
     <div class="navbar-header"> 
 
     <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse-2">  
 
      <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" id="logo" href="index.html"><img src="img/logo9.png" alt="Logo"></a> 
 
     </div> 
 
     <div class="collapse navbar-collapse" id="navbar-collapse-2"> 
 
     <ul class="nav navbar-nav navbar-right"> 
 
      <li class="active"><a href="#">Home</a></li> 
 
      <li><a href="about.html">About</a></li> 
 
      <li><a href="portfolio.html">Portfolio</a></li> 
 
      <li><a href="#">Blog</a></li> 
 
      <li><a href="contact.html">Contact</a></li> 
 
      <li><a href="#">Hire Me</a></li> 
 
     </ul> 
 
     </div> 
 
     <!-- /.navbar-collapse --> 
 
    </div> 
 
    <!-- /.container --> 
 
    </nav> 
 
    <!-- /.navbar --> 
 
    <div id="myname"> 
 
    <h1 class="quotes">I am <span style="color: #07d4de">Creative</span></h1> 
 
    <h1 class="quotes">I am <span style="color: #07d4de">Smart</span></h1> 
 
    <h1 class="quotes">I am <span style="color: #07d4de">Awesome</span></h1> 
 
    <h1 class="quotes">I am <span style="color: #07d4de">Olawale</span></h1> 
 
    </div> 
 
</section>

+0

是可以解決它,謝謝你。絕對和相對的定位對我來說一直是個問題。我總是搞錯了。 –