调整屏幕大小时无法使我的视频背景保持不变
我是 CSS 新手。我目前正在测试视频背景,当我缩小屏幕大小或打开开发工具时,无法使视频背景保持相同大小。每当我缩小屏幕时,背景就会变小。
谁能帮我弄清楚如何使我的视频背景具有响应性并使其无论屏幕大小如何都保持相同的大小,好吗?
这是我目前的视频背景样式:
video {
z-index: -1000;
left: 50%;
max-width: 100%;
position: absolute;
top: 50%;
transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
.showcase {
display: block;
height: auto;
overflow: hidden;
position: relative;
padding-bottom: 100%;
}
我的身体没有任何样式。我的视频标签位于展示标签内。
这就是我的视频背景的渲染方式:
function Main() {
return (
<>
<section id="showcase">
<video src="clouds.mp4" muted loop autoPlay></video>
<QuoteBox />
</section>
</>
);
}
I'm new at CSS. I'm testing out video backgrounds at the moment and I'm unable to have the video background stay the same size when I resize my screen smaller or open my dev tools. The background becomes smaller whenever I make my screen smaller.
This is what the background looks like when the screen is smaller
Can anyone help me figure out how to make my video background responsive and make it stay the same size no matter the size of the screen, please?
This is the styling I currently have for my video background:
video {
z-index: -1000;
left: 50%;
max-width: 100%;
position: absolute;
top: 50%;
transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
.showcase {
display: block;
height: auto;
overflow: hidden;
position: relative;
padding-bottom: 100%;
}
I do not have any styling for my body. And my video tag sits inside showcase tag.
This is how my video background is being rendered:
function Main() {
return (
<>
<section id="showcase">
<video src="clouds.mp4" muted loop autoPlay></video>
<QuoteBox />
</section>
</>
);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不同的视口将具有不同的宽高比,因此如果顶部/底部或侧面没有一些空间,视频并不总是完全适合内部。
由于在这种情况下让视频填满整个屏幕更为重要,因此此代码段说明了在视频元素上使用 CSS
object-fit: cover
,并将尺寸设置为整个视口。Different viewports will have differing aspect ratios and so the video will not always fit exactly inside without some space at the top/bottom or the sides.
As it is more important in this case to have the video filling the whole screen, this snippet illustrates using CSS
object-fit: cover
on the video element with the dimensions set to the whole viewport.