0

The video is in the header, and the proportions of the container is variable as the width is 100%, and the height is 65vh, and the video must cover the whole container by cropping top-bottom, or left-right.

I can do this by local video using: object-fit: cover, but this is not working with YouTube iframe.

.wp-custom-header {
    position: relative;
    overflow: hidden;
    width: 100vw;
    height: 65vh;
}
.wp-custom-header video,
.wp-custom-header iframe {
/* may be video or iframe depends if the user uploads a video, or insert YouTube */
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  object-fit: cover;
}
<div id="wp-custom-header" class="wp-custom-header">
<iframe id="wp-custom-header-video" allowfullscreen="1" title="YouTube video player" src="https://www.youtube.com/embed/rzfmZC3kg3M?autoplay=1&amp;controls=0&amp;disablekb=1&amp;fs=0&amp;iv_load_policy=3&amp;loop=1&amp;modestbranding=1&amp;playsinline=1&amp;rel=0&amp;showinfo=0&amp;enablejsapi=1&amp;origin=http%3A%2F%2Flocalhost&amp;widgetid=1" allow="accelerometer; encrypted-media; gyroscope; picture-in-picture" width="1920" height="677" frameborder="0"></iframe><button type="button" id="wp-custom-header-video-button" class="wp-custom-header-video-button wp-custom-header-video-pause" style="z-index: 9999999;position: relative;">Play</button>
</div>
Botond Vajna
  • 1,295
  • 1
  • 10
  • 22
  • 1
    Does this answer your question? [Force iframe YouTube video to center fit and full cover the screen in the background using HTML5 CSS3](https://stackoverflow.com/questions/24579785/force-iframe-youtube-video-to-center-fit-and-full-cover-the-screen-in-the-backgr) – avocadoLambda Jun 06 '20 at 11:13
  • not really, this is not a full-screen video, with fixed position, I am tring to implement it to my case, I`l be back if I have some results – Botond Vajna Jun 06 '20 at 12:08

1 Answers1

1

Take a look at this. Is it helpful? btw please share something that i can understand the problem more.

* { box-sizing: border-box; }
.video-background {
  background: #000;
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  z-index: -99;
}
.video-foreground,
.video-background iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
#vidtop-content {
 top: 0;
 color: #fff;
}
.vid-info { position: absolute; top: 0; right: 0; width: 33%; background: rgba(0,0,0,0.3); color: #fff; padding: 1rem; font-family: Avenir, Helvetica, sans-serif; }
.vid-info h1 { font-size: 2rem; font-weight: 700; margin-top: 0; line-height: 1.2; }
.vid-info a { display: block; color: #fff; text-decoration: none; background: rgba(0,0,0,0.5); transition: .6s background; border-bottom: none; margin: 1rem auto; text-align: center; }
@media (min-aspect-ratio: 16/9) {
  .video-foreground { height: 300%; top: -100%; }
}
@media (max-aspect-ratio: 16/9) {
  .video-foreground { width: 300%; left: -100%; }
}
@media all and (max-width: 600px) {
.vid-info { width: 50%; padding: .5rem; }
.vid-info h1 { margin-bottom: .2rem; }
}
@media all and (max-width: 500px) {
.vid-info .acronym { display: none; }
}
<div class="video-background">
    <div class="video-foreground">
      <iframe src="https://www.youtube.com/embed/W0LHTWG-UmQ?controls=0&showinfo=0&rel=0&autoplay=1&loop=1&playlist=W0LHTWG-UmQ" frameborder="0" allowfullscreen></iframe>
    </div>
  </div>

<div id="vidtop-content">
<div class="vid-info">
   <h1>YouTube Fullscreen Background Demo</h1>
   <p>The International Space Station orbits the Earth every 92 minutes, with its crew seeing a sunrise 15 times a day. It exists as a scientific, educational, and engineering platform in low orbit, 330 to 435 kilometres above the Earth.
     <p>Original timelapse by Riccardo Rossi (ISAA), used under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Raw photos courtesy of http://eol.jsc.nasa.gov/
  <a href="/500/Use-YouTube-Videos-as-Fullscreen-Web-Page-Backgrounds">Full article</a>
  </div>
</div>
SoliMoli
  • 781
  • 2
  • 6
  • 25