我试图添加一个全屏视频到一个网站,但我有困难,它涵盖整个屏幕。
最初,我尝试使用视频标签,但这在android上无法正常工作。现在我正在尝试iframes,我使用的CSS是:
iframe {
position: fixed;
top: 50%;
left: 50%;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
-ms-transform: translateX(-50%) translateY(-50%);
-moz-transform: translateX(-50%) translateY(-50%);
-webkit-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
background: url(polina.jpg) no-repeat;
background-size: cover;
}无论如何,视频上方/下面总是有额外的备份空间。
不管怎么说,我可以让视频填满整个屏幕,高兴地从侧面松开一些。
测试url是这里。
发布于 2016-04-01 10:33:38
我实际上找到了这个链接,它提供的代码实现了!http://fvsch.com/code/video-background/!
#video-bg {
position: fixed;
top: 0; right: 0; bottom: 0; left: 0;
overflow: hidden;
}
#video-bg > video {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
/* 1. No object-fit support: */
@media (min-aspect-ratio: 16/9) {
#video-bg > video { height: 300%; top: -100%; }
}
@media (max-aspect-ratio: 16/9) {
#video-bg > video { width: 300%; left: -100%; }
}
/* 2. If supporting object-fit, overriding (1): */
@supports (object-fit: cover) {
#video-bg > video {
top: 0; left: 0;
width: 100%; height: 100%;
object-fit: cover;
}
}发布于 2016-03-26 15:39:53
将width: 1920px;和height: 816px;添加到代码中,它就能工作了!
iframe {
position: fixed;
top: 50%;
left: 50%;
width: 1920px;
height: 816px;
-ms-transform: translateX(-50%) translateY(-50%);
-moz-transform: translateX(-50%) translateY(-50%);
-webkit-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
}或者,这可能是一个没有iframe的解决方案的起点。
html,
body {
margin: 0;
padding: 0;
}
video {
object-fit: cover;
width:100%;
min-height:100%;
}<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<video width="1920" height="816" preload="auto" autoplay loop>
<source src="http://dev.charlyanderson.co.uk/OnePointEight/wp-content/uploads/2016/03/BLKLOGO.m4v" type="video/mp4">
</video>
</body>
</html>
https://stackoverflow.com/questions/36236290
复制相似问题