After looking at existing answers, as well as other online tutorials, I still can't figure out how to position text over an image upon hover. Here is an example of what the image would look like when the cursor hovers over the image:
My current code is as follows:
.project {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.project img {
margin-top: 3em;
width: 27em;
height: 25em;
position: relative;
}
.project img:hover .project p, .project img:hover .project h4 {
opacity: 1;
}
.project p, .project h4 {
background: rgba(0,0,0,0.5);
color: white;
height: 25em;
width: 27em;
position: absolute;
top: 0;
left: 0;
opacity: 0;
}
<div id="project_section">
<div class="container">
<div class="row">
<h2>PROJECTS</h2>
<div class="col-sm-6 project">
<img src="https://www.planwallpaper.com/static/images/desktop-year-of-the-tiger-images-wallpaper.jpg" alt="">
<h4>Name</h4>
<p>Put some information here...</p>
</div>
<div class="col-sm-6 project">
<img src="https://cdn.pixabay.com/photo/2016/03/28/12/35/cat-1285634_960_720.png" alt="">
<h4>Namep</h4>
<p>Put some information here...</p>
</div>
</div>
</div>
</div>
In its current state, the text does not appear at all when hovering over the image. What am I missing?