我想在我的網站上創建一個全屏視頻背景,理想情況下只使用HTML和CSS。我還需要將視頻背景粘貼到頁面的頂部,因此用戶的第一個視圖完全被視頻覆蓋,然後他們可以向下滾動並移動視頻。全屏HTML5無JS視頻背景
我需要視頻響應並保持寬高比。但是,爲了避免黑條,我希望視頻能夠填充其中任何尺寸(寬度或高度)最小的100%,然後將視頻溢出其他尺寸。
這是我的解決方案至今...
<div class="container-fluid adjustedHeight">
<div class="video-container">
<div class="row">
<div class="col-md-12"></div>
</div>
<div class="row Page1">
<div class="col-md-6 button1">
<button type="button" class="btn btn-primary btn-lg outline">Pre-Order</button>
</div>
<div class="col-md-6 button2">
<button type="button" class="btn btn-primary btn-lg outline">About Us</button>
</div>
</div>
<video autoplay loop class="fillWidth">
<source src="Images/Comp 2.mp4" type="video/mp4" />
Your browser does not support the video tag. I suggest you upgrade your browser.</video>
<div class="poster hidden"> <img src="http://www.videojs.com/img/poster.jpg" alt=""> </div>
</div>
</div>
CSS:
.video-container {
position: relative;
bottom: 0%;
left: -15px;
height: 100% !important;
width: 100vw;
overflow: hidden;
background: #000;
display: block !important;
}
.video-container video {
position: absolute;
z-index: 0;
bottom: 0;
}
.video-container video.fillWidth {
min-width: 100%;
min-height: 100%;
}
它適用於寬度,但我得到的黑條,如果高度過大,視頻,即寬度不會溢出。我如何定義這個以確保寬度和高度至少100%填充?我認爲min-height
和min-width
屬性會這樣做,但這會將高度和寬度都調整到100%以上,並且在調整大小時,視頻不會縮放,只會截斷更多視頻的寬度(並且不會保留視頻中心)。而如果我只使用.video-container video.fillWidth
CSS屬性中的寬度和高度定義,我確實獲得了視頻集中,但是我得到了黑條。
這是一個JSFiddle它目前顯示當高寬比與視口比率不同時,黑條出現在上方和下方(也在左側和右側,但很難看到)。
注意:我使用引導程序3,我的adjustedheight
屬性允許導航欄的空間。
編輯:
要回答的關閉請求,該鏈接的問題已經回答了需要JS,我不想使用。
感謝您的幫助,我真的很想要得到一項決議,這是似乎基於什麼我的代碼應該這樣做是有道理的不 - 不知道我要去的地方錯了...
有沒有人有任何想法?由於我JSFiddle一切似乎已經安靜...
嘗試把你的'視頻container'身體標記和使用 * { 保證金= 0; padding = 0; } – Lakshya
[可以將HTML5 作爲全屏幕背景顯示嗎?](http://stackoverflow.com/questions/3899865/can-you-display-html5-video-as-a-full-screen-背景) – Rob
@Rob這些似乎主要包括JS? –