2015-10-25 186 views
0

我是bootstrap的初學者,我一直在嘗試使用它來爲我的網站創建主頁。我現在面臨的問題是這樣的:Bootstrap:與jumbotron重疊的div

Image

三個圖像重疊的超大屏幕,我想不通爲什麼。以下是HTML代碼:

<!--navigation bar--> 
<div class="navbar-wrapper"> 


    <nav class="navbar navbar-inverse navbar-static-top"> 
     <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="logo" href="#"><img src="C:\Users\Mickey.Utopia\Documents\EdHoc\temp-logo.jpg" height= "50" width = "80"></a> 
     </div> 
     <div class="navbar-collapse collapse navbar-right"> 
      <ul class="nav navbar-nav"> 
      <!-- 
      <li class="active"><a href="#">Home</a></li> 
      --> 
      <li class = "animate"><a href="#about">About</a></li> 
      <li><a href="#contact">Contact</a></li> 
      <li><a href = "C:\Users\Mickey.Utopia\Documents\EdHoc\Sign_in.htm">Sign In</a></li> 
      <li><a href = "#">Sign Up</a></li> 
      </ul> 
     </div> 
     </div> 
    </nav> 
</div> 



<div class='jumbotron' > 
<div class="container"> 
    <div class="row"> 
    <div class="col-xs-12 col-lg-12 col-sm-12" > 
     <h1 id="jumb">Welcome to EdHoc. <br>Discover the best places to learn and collaborate with friends to make learning easier.</h1> 
      </div> 
      <div class="row"> 
       <div class="col-xs-8 col-lg-8 col-sm-8" id="search"> 
       <!--Search Bar here--> 
       <input type="text" class="form-control" placeholder="Search by location, institute, discipline" id="srcb"> 
       <!--Button--> 
       </div> 
       <div class="col-xs-4 col-lg-4 col-sm-4" id="button"> 
        <a href="" class="btn btn-default">Go</a> 
       </div> 
      </div> 
      </div> 
     </div> 
     </div> 
     <hr> 

     <div class="container marketing"> 

    <!-- Three columns of text below the jumbotron --> 
    <div class="row"> 
    <div class="col-sm-8 col-xs-12 col-lg-4"> 
     <img class="img-circle" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="Generic placeholder image" width="140" height="140"> 
     <h2>Heading</h2> 
     <p>Donec sed odio dui. Etiam porta sem malesuada magna mollis euismod. Nullam id dolor id nibh ultricies vehicula ut id elit. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Praesent commodo cursus magna.</p> 
     <p><a class="btn btn-default" href="#" role="button">View details &raquo;</a></p> 
    </div><!-- /.col-lg-4 --> 
    <div class="col-lg-4"> 
     <img class="img-circle" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="Generic placeholder image" width="140" height="140"> 
     <h2>Heading</h2> 
     <p>Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Cras mattis consectetur purus sit amet fermentum. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh.</p> 
     <p><a class="btn btn-default" href="#" role="button">View details &raquo;</a></p> 
    </div><!-- /.col-lg-4 --> 
    <div class="col-lg-4"> 
     <img class="img-circle" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="Generic placeholder image" width="140" height="140"> 
     <h2>Heading</h2> 
     <p>Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p> 
     <p><a class="btn btn-default" href="#" role="button">View details &raquo;</a></p> 
    </div><!-- /.col-lg-4 --> 
    </div><!-- /.row --> 

<!-- Bootstrap core JavaScript 
================================================== --> 
<!-- Placed at the end of the document so the pages load faster --> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 
<script src="\bootstrap-3.3.5-dist\bootstrap-3.3.5-dist\js\bootstrap.min.js"></script> 

<!-- IE10 viewport hack for Surface/desktop Windows 8 bug --> 
<script src="../../assets/js/ie10-viewport-bug-workaround.js"></script> 

相關的CSS(除了引導文件):

.navbar { 
background-color: transparent; 
border: none; 
} 
.jumbotron { 
height: 400px; 
background-image: url(../images/woman.jpg); 
background-size: cover; 
border: none; 
width: 100%; 
position: absolute; 
top:0; 
z-index: -100; 
} 

#jumb { 
color: white; 
font-size: 20px; 
} 

我該如何解決這個問題?

+0

你本地開發,或者你可以把鏈接發給站點着中的jsfiddle等複製,可以採取在檢查快看? – AdamJeffers

+0

請不要在這裏要求緊急回覆 - 關於Stack Overflow的問題以及網上的任何地方都由志願者回答,我們認爲所有問題同等重要。 – halfer

+0

打開檢查器,然後右鍵單擊灰色圓圈並選擇檢查元素。它應該突出顯示html中的元素,並從那裏排除故障。可能是這個? –

回答

1

你有你的jumbotron股利用位置:絕對這就是爲什麼它下面的內容重疊。見下列參考文獻:

position:absolute;元素的位置:絕對;定位爲 相對於最近定位的祖先(而不是相對於視口定位 ,如固定)。

但是;如果絕對定位元素沒有定位 祖先,則它使用文檔主體,並隨着頁面滾動移動頁面 。

注意:「定位」元素的位置是除靜態以外的任何東西。

而且

重疊的元素 當元件被定位,它們可以重疊其它 元件。

z-index屬性指定元素的堆棧順序(其中 元素應放置在其他元素的前面或後面)。

一個元素可以有正面或負面的堆疊順序:

Absolute, Relative, Fixed Positioning: How Do They Differ?

*您也有一些結構性的矛盾,如col-sm-8 col-xs-12 col-lg-4這是沒有意義的地方,以較大的尺寸之間的最小斷點大小:請參閱Grid

您應該首先查閱文檔,瞭解這些組件的結構以及它們如何相互交互。 Docs

.navbar.navbar-custom { 
 
    background: none; 
 
    border: none; 
 
    margin-bottom: -50px; 
 
} 
 
div.jumbotron { 
 
    height: 400px; 
 
    background-image: url(http://interiorofficesystems.com/wp-content/themes/ios/uploads/product_photo/afe3a3ed124cb421preview%20-%20114371%20-%20Tayco_View02.jpg); 
 
    background-size: cover; 
 
    border: none; 
 
} 
 
div.jumbotron .jumb { 
 
    margin-bottom: 20px; 
 
    color: white; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> 
 
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" /> 
 
<nav class="navbar navbar-inverse navbar-static-top navbar-custom"> 
 
    <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="logo" href="#"> 
 
     <img src="http://placehold.it/80x50/266080/fff" height="50" width="80"> 
 
     </a> 
 

 
    </div> 
 
    <div class="collapse navbar-collapse" id="navbar"> 
 
     <ul class="nav navbar-nav navbar-right"> 
 
     <li class="animate"><a href="#about">About</a> 
 

 
     </li> 
 
     <li><a href="#contact">Contact</a> 
 

 
     </li> 
 
     <li><a href="C:\Users\Mickey.Utopia\Documents\EdHoc\Sign_in.htm">Sign In</a> 
 

 
     </li> 
 
     <li><a href="#">Sign Up</a> 
 

 
     </li> 
 
     </ul> 
 
    </div> 
 
    </div> 
 
</nav> 
 
<div class='jumbotron'> 
 
    <div class="container"> 
 
    <div class="jumb"> 
 
     <h1>Welcome to EdHoc.</h1> 
 
     <br> 
 
     <p>Discover the best places to learn and collaborate with friends to make learning easier.</p> 
 
    </div> 
 
    <div class="input-group input-group-lg"> 
 
     <input type="text" id="search" class="form-control" placeholder="Search by location, institute, discipline" id="srcb"> <span class="input-group-btn"> 
 
     <button class="btn btn-default btn-lg" id="button" type="button">Go!</button> 
 
     </span> 
 

 
    </div> 
 
    </div> 
 
</div> 
 
<div class="container text-center"> 
 
    <div class="row"> 
 
    <div class="col-sm-4"> 
 
     <img class="img-circle" src="http://placehold.it/200x200/000" alt="Generic placeholder image" width="140" height="140"> 
 
     <h2>Heading</h2> 
 

 
     <p>Donec sed odio dui. Etiam porta sem malesuada magna mollis euismod. Nullam id dolor id nibh ultricies vehicula ut id elit. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Praesent commodo cursus magna.</p> <a class="btn btn-default" 
 
     href="#" role="button">View details &raquo;</a> 
 

 
    </div> 
 
    <div class="col-sm-4"> 
 
     <img class="img-circle" src="http://placehold.it/200x200/000" alt="Generic placeholder image" width="140" height="140"> 
 
     <h2>Heading</h2> 
 

 
     <p>Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Cras mattis consectetur purus sit amet fermentum. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh.</p> <a class="btn btn-default" 
 
     href="#" role="button">View details &raquo;</a> 
 

 
    </div> 
 
    <div class="col-sm-4"> 
 
     <img class="img-circle" src="http://placehold.it/200x200/000" alt="Generic placeholder image" width="140" height="140"> 
 
     <h2>Heading</h2> 
 

 
     <p>Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p> 
 
     <a 
 
     class="btn btn-default" href="#" role="button">View details &raquo;</a> 
 

 
    </div> 
 
    </div> 
 
</div>

+0

謝謝。儘管它帶來了一個新問題,但您的更改解決了最初的問題。刪除「position:absolute」會導致jumbotron放置在導航欄下方,但我想讓導航欄與jumbotron重疊。如果我刪除絕對財產,我將如何繼續這樣做? – user3650571

+0

我在昨天發佈的答案中沒有看到這個問題,最初是這樣,然後我將圖像轉回到您發佈的圖像上,並將其更改爲圖像位於導航欄下方,而不是下方,請再次參閱片段。 – vanburen