2016-11-14 80 views
0

我正在學習網絡開發,並試圖建立一個網站。我試圖製作一個輪播,但與YouTube視頻。我擁有的是工作,但它拒絕調整我的需求。爲什麼我的YouTube嵌入拒絕在視頻輪播中調整大小?

這就是我得到的。廣泛但短小的視頻。 This is what I'm getting. A wide but short video size.

但這就是我想要的,離全屏最近,但我想保留來自旋轉木馬的左/右導航,並讓它們出現在視頻內容的頂部。 enter image description here

這裏是我的代碼:PLS,看看:

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <title>Bootstrap Example</title> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
    <style> 
    .carousel-inner > .item > iframe, 
    .carousel-inner > .item > a > img { 
     width: 100%; 
     margin: auto; 
    } 
    </style> 
</head> 
<body style="height:100%;"> 

<div style="height:100%;"> 
    <div id="myCarousel" class="carousel slide" data-ride="carousel" style="height:100%;"> 
    <!-- 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" style="height:100%;"> 

     <div class="item active" style="height:100%;"> 
     <iframe width="100%" height="100%" src="https://www.youtube.com/embed/UTt33udwRw0?autoplay=1" frameborder="0" allowfullscreen></iframe> 
     </div> 

     <div class="item" style="height:100%;"> 
     <iframe width="100%" height="100%" src="https://www.youtube.com/embed/UTt33udwRw0?autoplay=1" frameborder="0" allowfullscreen></iframe> 
     </div> 

     <div class="item" style="height:100%;"> 
     <iframe width="100%" height="100%" src="https://www.youtube.com/embed/UTt33udwRw0?autoplay=1" frameborder="0" allowfullscreen></iframe> 
     </div> 

     <div class="item" style="height:100%;"> 
     <iframe width="100%" height="100%" src="https://www.youtube.com/embed/UTt33udwRw0?autoplay=1" frameborder="0" allowfullscreen></iframe> 
     </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> 

</body> 
</html> 

回答

2

height:100%是相對父元素。在這種情況下,html是父元素,並沒有定義的高度。如果添加height:100%;html標籤的CSS它應該工作:

<!DOCTYPE html> 
 
<html lang="en" style="height:100%;"> 
 
<head> 
 
    <title>Bootstrap Example</title> 
 
    <meta charset="utf-8"> 
 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
 
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
 
    <style> 
 
    .carousel-inner > .item > iframe, 
 
    .carousel-inner > .item > a > img { 
 
     width: 100%; 
 
     margin: auto; 
 
    } 
 
    </style> 
 
</head> 
 
<body style="height:100%;"> 
 

 
<div style="height:100%;"> 
 
    <div id="myCarousel" class="carousel slide" data-ride="carousel" style="height:100%;"> 
 
    <!-- 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" style="height:100%;"> 
 

 
     <div class="item active" style="height:100%;"> 
 
     <iframe width="100%" height="100%" src="https://www.youtube.com/embed/UTt33udwRw0?autoplay=1" frameborder="0" allowfullscreen></iframe> 
 
     </div> 
 

 
     <div class="item" style="height:100%;"> 
 
     <iframe width="100%" height="100%" src="https://www.youtube.com/embed/UTt33udwRw0?autoplay=1" frameborder="0" allowfullscreen></iframe> 
 
     </div> 
 

 
     <div class="item" style="height:100%;"> 
 
     <iframe width="100%" height="100%" src="https://www.youtube.com/embed/UTt33udwRw0?autoplay=1" frameborder="0" allowfullscreen></iframe> 
 
     </div> 
 

 
     <div class="item" style="height:100%;"> 
 
     <iframe width="100%" height="100%" src="https://www.youtube.com/embed/UTt33udwRw0?autoplay=1" frameborder="0" allowfullscreen></iframe> 
 
     </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> 
 

 
</body> 
 
</html>

我也建議使用style代碼或外部的樣式表,而不是內聯CSS,因爲它更易於管理。

+0

我不知道html標籤本身可能有屬性。非常感謝 - 現在工作。 :) –