2016-04-19 143 views
0

我想添加bootstrap旋轉木馬,當我檢查元素時,dom可用但它沒有顯示出來。Bootstrap Carousel沒有顯示在頁面上

我使用的是定製的引導庫,我下載表格此鏈接:

BootStrap Custom Link

我在我的模板很想念。

這是我的嘗試:

HTML:

<div id="myCarousel" class="carousel slide" data-ride="carousel"> 
     <!-- Indicators --> 
     <ol class="carousel-indicators"> 
     <li data-target="#myCarousel" data-slide-to="0" class="active"></li> 
     <li data-target="#myCarousel" data-slide-to="1" class=""></li> 
     <li data-target="#myCarousel" data-slide-to="2" class=""></li> 
     </ol> 
     <div class="carousel-inner" role="listbox"> 
     <div class="item active"> 
      <img class="first-slide" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="First slide"> 
      <div class="container"> 
      <div class="carousel-caption"> 
       <h1>Example headline.</h1> 
       <p>Note: If you're viewing this page via a <code>file://</code> URL, the "next" and "previous" Glyphicon buttons on the left and right might not load/display properly due to web browser security rules.</p> 
       <p><a class="btn btn-lg btn-primary" href="#" role="button">Sign up today</a></p> 
      </div> 
      </div> 
     </div> 
     <div class="item"> 
      <img class="second-slide" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="Second slide"> 
      <div class="container"> 
      <div class="carousel-caption"> 
       <h1>Another example headline.</h1> 
       <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p> 
       <p><a class="btn btn-lg btn-primary" href="#" role="button">Learn more</a></p> 
      </div> 
      </div> 
     </div> 
     <div class="item"> 
      <img class="third-slide" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="Third slide"> 
      <div class="container"> 
      <div class="carousel-caption"> 
       <h1>One more for good measure.</h1> 
       <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p> 
       <p><a class="btn btn-lg btn-primary" href="#" role="button">Browse gallery</a></p> 
      </div> 
      </div> 
     </div> 
     </div> 
     <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev"> 
     <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> 
     <span class="sr-only">Previous</span> 
     </a> 
     <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next"> 
     <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> 
     <span class="sr-only">Next</span> 
     </a> 
    </div> 

JS:

$('#myCarousel').carousel(); 

Fiddle Demo

回答

4

每一件事情就是在你的代碼罰款只是你需要有圖像的高度和下面的CSS寬度用它可以解決您的問題。

.carousel-inner > .item >img{ 
    min-height : 300px; 
    max-height : 300px; 
    width : 100%; 
} 
2

只需要給予高度如下.container類:

.container{ 
    height:300px; 
} 

但是,我寧願將container類名更改爲custom-container。因爲bootstrap已經使用container作爲類名。所以最好遠離預期的衝突。

這裏工作的jsfiddle https://jsfiddle.net/68hf5y33/3/

+0

您無法修復容器高度,因爲它會影響您使用相同類別的位置 –