[英]CSS positioning/resizing html5 video background
為防止出現此問題,您需要執行以下操作:
css:
.div1{ background-color: red; height: 100%; position: relative; overflow: hidden;}
.div2{ background-color: black; height: 100%;}
video{ position: absolute; height: 100%; width: 100%; margin: 0; padding: 0; top: 0; bottom:0; right: 0; left: 0;}
並將您的視頻放在 div1 中:
<div class="div1">
<video autoplay>...</video>
</div>
<div class="div2">
</div>
它不允許視頻元素在溢出時顯示。 div1 總是高度:100%,div2 總是高度:100%。
如果你想讓視頻適合 div1 添加
object-fit: cover;
到視頻標簽。
IE 不支持對象匹配
我不確定這是否可行,但是您是否嘗試過刪除 width: 100% 並只保留 height: 100% ?
如果您可以顯示代碼,我可能會提供更好的建議:p
編輯:由於您希望高度為屏幕高度和寬度可以或多或少,我想說,嘗試
min-height: 100%;
width: auto;
height: auto;
這應該可以解決問題
新編輯:
body{
overflow:hidden;
}
#wrapper {
width: 100%;
height: 100%;
}
.videoInsert {
min-height: 100%;
min-width: 100%;
height: auto;
width: auto;
position: absolute;
left: 0%;
top: 0%;
}
video{
display: inline-block;
vertical-align: baseline;
object-fit: fill;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.