【问题标题】:How to make my video responsive in website ? [html]如何让我的视频在网站上响应? [html]
【发布时间】:2021-11-07 02:49:33
【问题描述】:
有什么方法可以在<video>标签移动响应中制作视频吗?
<video autoplay muted loop id="myVideo">
<source src="rick.mp4" type="video/mp4">
</video>
<style>
#myVideo {
position: fixed;
right: 0;
bottom: 0;
min-width: 100%;
min-height: 100%;
}
</style>
【问题讨论】:
标签:
html
css
video
responsive-design
【解决方案1】:
请检查,我已通过以下方式进行视频响应。
第一个选项您可以使用媒体查询
<video autoplay muted loop id="myVideo">
<source src="https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4" type="video/mp4">
</video>
<style>
#myVideo {
position: fixed;
right: 0;
bottom: 0;
min-width: 100%;
max-height: 100%;
}
@media(max-width: 640px){
#myVideo {
width: 100%;
}
}
</style>
第二个选项设置width: 100%而不是min-width: 100%
<video autoplay muted loop id="myVideo">
<source src="https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4" type="video/mp4">
</video>
<style>
#myVideo {
position: fixed;
right: 0;
bottom: 0;
width: 100%;
max-height: 100%;
}
</style>
第三个选项为视频标签添加包装器并处理响应式
<div class="video-Wrapper">
<video autoplay muted loop id="myVideo">
<source src="https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4" type="video/mp4">
</video>
</div>
<style>
.video-Wrapper {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: #000;
}
#myVideo {
position: absolute;
right: 0;
bottom: 0;
width: 100%;
max-height: 100%;
}
</style>