Answers for "play youtube video in background html"

CSS
1

youtube as background video website

// HTML
<div class="embed-container">
	<iframe src="https://www.youtube.com/embed/9QTojZVR_Ec?controls=0&autoplay=1&mute=1" frameborder="0" mute="1" allow="autoplay;encrypted-media"></iframe>
</div>

// CSS
@media (min-aspect-ratio: 16/9) {
  .embed-container iframe {
    height: 56.25vw;
    width: 100vw;
  }
}
@media (max-aspect-ratio: 16/9) {
  .embed-container iframe {
    width: 177.78vh;
    height: 100vh;
  }
}
div.embed-container {
  z-index: -99;
  position: absolute;
  overflow: hidden;
  width: 100vw;
  height: 100vh;
}
div.embed-container iframe {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

// or... SASS (same as CSS but different syntax)
@media (min-aspect-ratio: 16/9)
  .embed-container iframe
    height: 56.25vw
    width: 100vw

@media (max-aspect-ratio: 16/9)
  .embed-container iframe
    width: 177.78vh
    height: 100vh

div.embed-container
  z-index: -99
  position: absolute
  overflow: hidden
  width: 100vw
  height: 100vh
  iframe
    position: absolute
    top: 50%
    left: 50%
    transform: translate(-50%, -50%)
Posted by: Guest on October-21-2020
0

youtube video background html

/*HTML*/
<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>

/*css:*/
* { 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; }
}
Posted by: Guest on October-08-2021

Code answers related to "play youtube video in background html"

Browse Popular Code Answers by Language