我希望以100%宽度和自动高度显示响应式html5视频,使其上方的空间等于所有屏幕和设备上方的空间。这是我的代码。
body,
video {
border: 0;
margin: 0;
padding: 0;
}
body {
background-color: black;
}
video {
width: 100%;
height: auto;
}

<video controls>
<source src="https://www.w3schools.com/html/mov_bbb.mp4">
</video>
&#13;
我尝试用不同的想法来实现这一点,比如设置边距,但都失败了。如有必要,我愿意接受javascript / jquery / plugins。
答案 0 :(得分:2)
您可以通过以下方式集中使用flexbox CSS来实现此目的:
html {
height: 100%;
}
body {
background-color: black;
height: 100%;
margin: 0;
display: flex;
align-items: center;
}
video {
width: 100%;
height: auto;
}
&#13;
<video controls>
<source src="https://www.w3schools.com/html/mov_bbb.mp4">
</video>
&#13;
答案 1 :(得分:1)
看看at how bootstrap achieves this.他们使用包装div来控制尺寸,并将视频设置为绝对定位,宽度和高度均为100%。它比Jon的解决方案更灵活一些,尽管它可以做你想要的。