Lat*_*ral 5 html css browser video resize
我正在尝试创建一个背景为视频的网站.我一直在寻找如何重新创建像Spotify的主页背景这样的东西,但似乎无法使它工作.
我的问题是,我可以通过浏览器或宽度获得高度,但不能同时获得两者.与Spotify网站上的视频不同,它无法随时扩展以适应浏览器.我尝试了很多东西,其中大部分我都记不起来了.我不介意使用JQuery来实现这种效果.
我目前的代码是:
<!DOCTYPE html>
<html>
<head>
<title>VideoBG</title>
<style type="text/css">
#videohome {
position:absolute;
height: 100%;
width: 100%;
top:0;
left:0;
right:0;
bottom:0;
}
</style>
</head>
<body>
<video id="videohome" preload="auto" autoplay="true" loop="loop" muted="" volume="0">
<source src="./homepage.mp4" type="video/mp4" />
</video>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
小智 7
您将需要一个适合屏幕的容器div,然后在视频中添加一个类,将其调整为宽度或高度.
CSS:
.container {
width: 100%;
height: 100%;
position: absolute;
padding:0;
margin:0;
left: 0px;
top: 0px;
z-index: -1000;
overflow:hidden;
}
.videoPlayer {
min-height: 100%;
//min-width:100%; - if fit to width
position:absolute;
bottom:0;
left:0;
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<div class="container"><video class="videoPlayer">Code goes here</video></div>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19997 次 |
| 最近记录: |