<header>
<!-- First container -->
<div class="container container_solid">
<div class="title_wrapper">
<h1>The Great Outdoors</h1>
</div>
</div>
<!-- Second container -->
<div class="container container_image">
<div class="title_wrapper">
<h1>The Great Outdoors</h1>
</div>
</div>
</header>
.container {
height: 100vh;
}
.container_solid {
background: white;
}
.title_wrapper {
position: fixed;
display: block;
margin: auto;
width: 100%;
/* center the text wrapper vertically */
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
}
.title_wrapper h1 {
text-align: center;
}
.container_solid .title_wrapper h1 {
/* the text background */
background: url(https://images.unsplash.com/photo-1575058752200-a9d6c0f41945?&q=85);
background-size: 100vw auto;
background-position: center;
/* clip the text is possible */
text-fill-color: transparent;
-webkit-text-fill-color: transparent;
background-clip: text;
-webkit-background-clip: text;
/* fallback text color */
color: black;
}
.container_image {
/* Grab a free image from unsplash */
background-image: url(https://images.unsplash.com/photo-1575058752200-a9d6c0f41945?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ);
background-size:100vw auto;
background-position: center;
background-attachment: fixed;
}
.container_image .title_wrapper h1 {
color: white;
/* add some text shadow to view text positioning easier */
text-shadow: 2px 2px rgba(0,0,0,0.3);
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.