vue3中【html+css】背景设置为视频并铺满整个页面

Tip:<video>标签默认不是铺满的,手动设置宽高100%也不会生效,当需要video铺满div时,加上一个css样式

  • object-fit: fill

  1. object-fit 属性指定元素的内容应该如何去适应指定容器的高度与宽度。

  1. object-fit 一般用于 img 和 video 标签,一般可以对这些元素进行保留原始比例的剪切、缩放或者直接进行拉伸等。

  1. fill: 默认,不保证保持原有的比例,内容拉伸填充整个内容容器。

<template>
  <div class="box">
 <!-- autoplay 自动播放  loop循环播放  muted 声音 preload 预加载 -->
    <video autoplay loop muted preload 
    style="width: 100%; height: 100%; object-fit: fill">
      <source src="/images/bjsp.mp4">
    </video>
  </div>
</template>
<style scoped >
* {
  margin: 0;
  padding: 0;
}

.box {
  width: 100%;
  height:calc(100vh - 40px);
  background-color: rgb(141, 130, 130);
  position: relative;
}

video {
  height: calc(100vh - 40px);
  background-size:100% 100%;
  width: 100%;
  position: absolute;
  filter: blur(3px);
  top: 0;
  left: 0;
}

猜你喜欢

转载自blog.csdn.net/m0_67986791/article/details/129319426