Honestly, I think the easiest way is to just to use photoshop / [your favourite image editing software] to put the overlay text over the background image. I made this jsfiddle which hopefully demonstrates your desired behavior.
The HTML
<div class="media-screen">
<h1 class="sr-only">Overlay Text</h1>
<p class="sr-only">With an interesting paralax effect</p>
</div>
Where sr-only
is a class that hides elements visually while maintaining screen reader accessibility
The CSS
.media-screen {
position: relative;
height: 250px;
background-image: url('path/to/your/image.png');
background-position: center center;
background-repeat: no-repeat;
background-attachment: fixed;
}
.sr-only {
position: absolute;
overflow: hidden;
clip: rect(0 0 0 0);
height: 1px; width: 1px;
margin: -1px; padding: 0; border: 0;
}
Mobile Support
If you are supporting multiple screen sizes you will probably need a few different versions of the image to suit different orientations. You can use media queries to substitute the image that is displayed for various sizes / orientations
/*Example media query for view port width*/
@media screen only and (min-width: 1024px){
.media-screen {
background-image: url('path/to/your/image-large.png');
}
}
/* Example media query for view port orientation */
@media screen only and (orientation: portrait){
.media-screen {
background-image: url'path/to/your/image-narrow.png');
}
}
Note: Embedding content in the background image obviously means that the content is not interactive so this is only really any good for basic display elements.