Html5 video background, keep center of video in center

后端 未结 10 1357
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-23 12:00

I am trying to keep a background video centered regardless of how big the user drags the video. It\'s currently cutting off the right side of the videos when i scroll smalle

10条回答
  •  隐瞒了意图╮
    2020-12-23 12:27

    This worked for me

    .video_contain {
      position: absolute;
      z-index: -1;
      top: 0px;
      left: 0px;
      bottom: 0px;
      right: 0px;
      overflow: hidden;
      background-size: cover;
      background-repeat: no-repeat;
      background-position: 50% 50%;
      background-image: none;
    }
    
    #bgvid {
      margin: auto;
      position: absolute;
      z-index: -1;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      visibility: visible;
      width: 1267px;
      height: auto;
    }
    

提交回复
热议问题