I am using a large hero image that is absolutely positioned in order to place a text overlay on top of it. I have also ensured that the hero image is responsive no matter the dimensions of the screen. THe issue I am running into, is ensuring the overlay text is vertically centered within the background image no matter what the screen size.
The following link shows the effect I am trying to achieve with the overlay text: https://www.youtube.com/watch?v=gfzWLbAbcCw
My jsx code is as follows:
<>
<div className="container">
<div className="container-background">
<img
src="https://i.imgur.com/iyFtMNA.jpg"
alt="bg"
className="container-background-img"
/>
</div>
<div className="content">
<Navbar />
<div className="page-outer">
<div className="page-inner">
<div className="wel-top-header">text</div>
<div className="wel-top-middle">
<div style={{ marginTop: -30 }}>text</div>
<div style={{ marginTop: -48 }}>text</div>
</div>
<div className="wel-tagline">
Pagerland offers a great, smooth looking and ultra-fast landing
page templates build on Gatsby and React.
</div>
</div>
</div>
</div>
</div>
</>
my css code is as follows:
* {
margin: 0;
padding: 0;
}
.navbar {
height: 80px;
background-color: white;
display: flex;
justify-content: center;
align-items: center;
border: solid black 1px;
}
.container {
position: relative;
}
.container .container-background {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
opacity: 0.25;
}
the following link contains a code sandbox for debugging! https://codesandbox.io/s/charming-dijkstra-im7nb?file=/src/styles.scss:0-1101
any and all suggestions would be greatly appreciated