2016-04-18 198 views
0

我在asp.net中使用了引導程序傳送帶。我想設置旋轉木馬的寬度,以便它佔用具有固定高度的瀏覽器窗口的整個寬度,如果我將寬度更改爲100%,則不起作用。以下是旋轉木馬將輪播寬度動態設置爲窗口大小

<div id="myCarousel" class="carousel slide" data-ride="carousel" style="width:1177px; height:239px; top: 0px; left: 0px;"> 


<!-- Wrapper for slides --> 
<div class="carousel-inner" role="listbox" style="width:1177px; height:240px; top: 0px; left: 0px;"> 
<div class="item active"> 
    <img src='images/image1.jpg' alt="Chains" style="width:1177px"/> 
</div> 


<div class="item"> 
    <img src='images/image2.jpg' alt="Chains" style="width:1177px"/> 
</div> 

<div class="item"> 
    <img src='images/image3.jpg' alt="Chains" style="width:1177px"/> 
</div> 
    <div class="item"> 
    <img src='images/image4.jpg' alt="Chains" style="width:1177px"/> 
</div>  
</div> 
</div> 

我已經手動設置圖像的寬度和輪播到瀏覽器窗口中的代碼,但我想這是動態的。

以下是CSS

.carousel { 
position: relative; 
} 
.carousel-inner { 
position: relative; 
width: 100%; 
overflow: hidden; 
} 
.carousel-inner > .item { 
position: relative; 
display: none; 
-webkit-transition: .6s ease-in-out left; 
     transition: .6s ease-in-out left; 
} 
.carousel-inner > .item > img, 
.carousel-inner > .item > a > img { 
line-height: 1; 
width: 1177px; 
} 
.carousel-inner > .active, 
.carousel-inner > .next, 
.carousel-inner > .prev { 
display: block; 
} 
.carousel-inner > .active { 
left: 0; 
} 
.carousel-inner > .next, 
.carousel-inner > .prev { 
position: absolute; 
top: 0; 
width: 100%; 
} 
.carousel-inner > .next { 
left: 100%; 
} 
.carousel-inner > .prev { 
left: -100%; 
} 
.carousel-inner > .next.left, 
.carousel-inner > .prev.right { 
left: 0; 
} 
.carousel-inner > .active.left { 
left: -100%; 
} 
.carousel-inner > .active.right { 
left: 100%; 
} 

而且當我向右滾動的傳送帶亮起側邊欄的頂部。我如何避免這種情況。

回答

0

您必須給予所有寬度爲100%的寬度。

我可以看到一些7-8寬度:1177px在HTML代碼使所有爲width:100%

此外,在CSS化妝寬度:爲所有的類100%。

CODE:

<meta name="viewport" content="width=device-width, initial-scale=1"> 
 
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> 
 
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> 
 
<style> 
 
    .carousel-inner > .item > img, 
 
    .carousel-inner > .item > a > img { 
 
     width: 100%; 
 
     margin: auto; 
 
    } 
 
</style> 
 
<div class="container"> 
 
    <br> 
 
    <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"></li> 
 
     <li data-target="#myCarousel" data-slide-to="2"></li> 
 
     <li data-target="#myCarousel" data-slide-to="3"></li> 
 
    </ol> 
 

 
    <!-- Wrapper for slides --> 
 
    <div class="carousel-inner" role="listbox"> 
 
     <div class="item active"> 
 
     <img src="img_chania.jpg" alt="Chania" width="460" height="345"> 
 
     </div> 
 

 
     <div class="item"> 
 
     <img src="img_chania2.jpg" alt="Chania" width="460" height="345"> 
 
     </div> 
 
    
 
     <div class="item"> 
 
     <img src="img_flower.jpg" alt="Flower" width="460" height="345"> 
 
     </div> 
 

 
     <div class="item"> 
 
     <img src="img_flower2.jpg" alt="Flower" width="460" height="345"> 
 
     </div> 
 
    </div> 
 

 
    <!-- Left and right controls --> 
 
    <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> 
 
</div>

+0

我已經嘗試過,但它不@yatin –

+0

編輯工作,有工作的代碼 –

+0

您可以參考有關更多信息,HTTP答案://www.w3schools。 com/bootstrap/bootstrap_carousel.asp –

相關問題