Skip to content

Instantly share code, notes, and snippets.

@snsxn
Last active July 14, 2022 14:18
Show Gist options
  • Save snsxn/e0770863fc2544e7ea8c300e64b2de8c to your computer and use it in GitHub Desktop.
Save snsxn/e0770863fc2544e7ea8c300e64b2de8c to your computer and use it in GitHub Desktop.
Full width and height video background CSS
.bg-video {
position: fixed;
z-index: -1;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
@media (min-aspect-ratio: 16/9) {
.bg-video video {
width: 100%;
height: auto;
}
}
@media (max-aspect-ratio: 16/9) {
.bg-video video {
width: auto;
height: 100%;
}
}
<div class="bg-video">
<video autoplay muted loop poster="">
<source src="video.mp4" type="video/mp4">
</video>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment