Skip to content

Instantly share code, notes, and snippets.

@rahman541
Created September 25, 2023 09:36
Show Gist options
  • Save rahman541/60e7bf20ae77a731c69e0bb1e075ac5f to your computer and use it in GitHub Desktop.
Save rahman541/60e7bf20ae77a731c69e0bb1e075ac5f to your computer and use it in GitHub Desktop.
Full Screen Video with Text Overlay
<header class="video-header">
<video src="https://drive.google.com/uc?id=1QmPm1EdHE0yLepVKu8FqqpPxmNKSxwnC" autoplay loop playsinline muted></video>
<div class="header-text">
<h1>
Exploring
<span>The Sea</span>
</h1>
</div>
<div class="description">
<p>This is an example of a full screen video being shown as a background at any screen size.
This is accomplished with giving video absolute positioning, full viewport width and height, and using 'object-fit: cover;'
</p>
<p class="credit">Video credit: Taryn Elliot on <a href="https://www.pexels.com/video/colorful-fish-swimming-among-seaweed-5548030/">pexels.com.</a></p>
</div>
</header>
html, body {
font-family: 'Raleway', sans-serif;
background-color: teal;
}
video {
width: 100dvw;
min-height: 100dvh;
position: absolute;
top: 0;
left: 0;
object-fit: cover;
}
.header-text {
position: absolute;
color: white;
display: flex;
flex-direction: column;
justify-content: center;
text-align: center;
transform: translateY(-5rem);
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.header-text h1 {
font-weight: 400;
font-size: 1.75rem;
text-transform: uppercase;
line-height: 1;
}
.header-text span {
display: block;
font-weight: 900;
font-size: 6rem;
}
.description {
position: absolute;
bottom: 0;
left: 0;
right: 0;
margin: auto;
color: white;
background-color: hsl(181deg 50% 20% / 70%);
padding: 2rem;
}
.description p {
max-width: 40rem;
margin-inline: auto;
line-height: 1.6;
}
.credit {
font-size: .75rem;
}
.credit a {
color: white;
text-underline-offset: 2px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment