2

I am trying to fit the video background for all browsers including IE without zooming it. Here is my website URL:- https://my-developement.myshopify.com/

It works for most of the browser with CSS property object-fit: cover but IE doesn't support this property.

Please share your views on the issue.

adiga
  • 34,372
  • 9
  • 61
  • 83
Devl BRST
  • 41
  • 4
  • https://stackoverflow.com/questions/37792720/ie-and-edge-fix-for-object-fit-cover – Anatsu Jun 25 '19 at 11:00
  • 1
    Possible duplicate of [object-fit alternative for IE for a video with 100% width and set height](https://stackoverflow.com/questions/50541021/object-fit-alternative-for-ie-for-a-video-with-100-width-and-set-height) – frobinsonj Jun 25 '19 at 11:01

1 Answers1

1

With a tricky combination of vw/vh units, position and transform

.bg {
  position: absolute;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  display: flex;
  justify-content: center;
  z-index: -1;
  top: 0;
  left: 0;
}

video {
  width: 100vw;
  height: 100vh;
  min-height: calc(100vw * 9 / 16);
  min-width: calc(100vh * 16 / 9);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translateX(-50%) translateY(-50%);
}

body {
  margin: 0;
  font-family: sans-serif;
  font-size: 62.5%;
}

.foreground {
  margin: 30px auto;
  width: 60%;
  background-color: rgba(255, 255, 255, 0.3);
  padding: 20px;
}

h1 {
  font-size: 3rem;
  font-weight: 700;
  margin: 0;
}
<div class="bg">
  <video src="https://cdn.jsdelivr.net/npm/big-buck-bunny-1080p@0.0.6/video.mp4" autoplay muted loop></video>
</div>

<div class="foreground">
  <h1>Background Video Cover</h1>
</div>
yunzen
  • 32,854
  • 11
  • 73
  • 106