Created
February 3, 2019 23:29
-
-
Save d4rkyfirefly/3616ca2937580dfbd248fe48d68c16a9 to your computer and use it in GitHub Desktop.
responsive css video background
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> | |
| <link rel="stylesheet" type="text/css" href="styles.css"> | |
| </head> | |
| <body> | |
| <div id="textdiv"> | |
| <h1>Lorem ipsum</h1> | |
| <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur porta dictum turpis, eu mollis justo gravida ac. Proin non eros blandit, rutrum est a, cursus quam.</p> | |
| </div> | |
| <video id="videoBG" poster="poster.JPG" autoplay muted loop> | |
| <source src="footage1.mp4" type="video/mp4"> | |
| </video> | |
| </body> | |
| </html> | |
| ----- | |
| html,body { | |
| width:100vw; | |
| height: 100vh; | |
| margin: 0; | |
| } | |
| #videoBG { | |
| position:fixed; | |
| z-index: -1; | |
| } | |
| @media (min-aspect-ratio: 16/9) { | |
| #videoBG { | |
| width:100%; | |
| height: auto; | |
| } | |
| } | |
| @media (max-aspect-ratio: 16/9) { | |
| #videoBG { | |
| width:auto; | |
| height: 100%; | |
| } | |
| } | |
| @media (max-width: 767px) { | |
| #videoBG { | |
| display: none; | |
| } | |
| body { | |
| background: url('poster.jpg'); | |
| background-size: cover; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment