To set a video as the background of a div element, you can use the following CSS code:

div {
  position: relative;
  z-index: 1;
  overflow: hidden;
}

div video {
  position: absolute;
  top: 50%;
  left: 50%;
  min-width: 100%;
  min-height: 100%;
  width: auto;
  height: auto;
  transform: translate(-50%, -50%);
  z-index: -1;
}

In this code, we first set the div element to have a relative position, a z-index of 1, and an overflow of hidden to contain the video inside. Then, we set the video to have an absolute position, a top and left value of 50% to center it within the div, and a minimum width and height of 100% to cover the entire div. Finally, we use the transform property to move the video up and left by 50% of its own size, and set the z-index to -1 so it appears behind the content of the div.

To use this code, simply replace "div" with the class or ID of the element you want to set the video as the background of, and replace "video" with the HTML video element that contains the video you want to use

set div video background

原文地址: https://www.cveoy.top/t/topic/eJ6b 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录