After browsing through various solutions, I still can't seem to get my div and image layout to work as intended. I have a div with an image that fills the entire space (set to 100% for responsiveness). I'm trying to overlay some text on the image using an article element. However, I'm facing an issue where the text doesn't stay centered both horizontally and vertically when I resize the page. It aligns well horizontally but vertically it shifts out of place, affecting the content below (even though I haven't styled them yet). Any help or suggestions would be greatly appreciated. Thank you.
HTML:
<div class="featuredpost">
<img src="images/forest.jpg">
<div class="featured">
<article>
<header>
<h1><a href="#">Featured Post Goes Here</a></h1>
</header>
<footer>
<p class="postedby">Posted by User</p>
</footer>
<content>
<p>"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
<p>"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
</content>
<button type="button" onclick="alert('Hello world!')">Read More</button>
</article>
</div>
</div>
CSS:
.featuredpost{
width: 100%;
margin: 0 auto;
}
.featuredpost img{
width: 100%;
height: auto;
position: relative;
}
.featured{
margin: 0 auto;
width: 80%;
background-color: rgba(0,0,0,0.5);
color: #fff;
top: 50%;
position: absolute;
left: 10%;
}
.featured article{
padding: 10px 30px;
}