Hello!
I’m trying to create a hover image with text in the column / card next to it. I’m not sure where I’m going wrong, but every time I add in the hover image to my 2-column card layout code, the text ends up underneath the image in the same column. Can someone help me figure out what I need to fix in my code? Thanks so much!
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
box-sizing: border-box;
}
body {
font-family: Arial, Helvetica, sans-serif;
}
.column {
float: left;
width: 25%;
padding: 0 10px;
}
.row {margin: 0 -5px;}
.row:after {
content: "";
display: table;
clear: both;
}
@media screen and (max-width: 600px) {
.column {
width: 100%;
display: block;
margin-bottom: 20px;
}
}
.card {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
padding: 16px;
text-align: center;
background-color: #f1f1f1;
}
* {
box-sizing: border-box;
}
.column {
float: left;
width: 33.33%;
padding: 5px;
}
.row::after {
content: "";
clear: both;
display: table;
}
.container {
position: relative;
width: 150%;
}
.image {
display: block;
width: 100%;
height: auto;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: #008CBA;
}
.container:hover .overlay {
opacity: 1;
}
.text {
color: white;
font-size: 20px;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
}
</style>
</head>
<body>
<h2>First Grade Team</h2>
<p>Get to know more about our first grade teachers</p>
<div class="row">
<div class="column">
<div class="card">
<div class="container">
<img src="https://springhilles.fcps.edu/sites/default/files/styles/gallery/public/galleries/2022-08/IMG-2217.JPEG?h=d318f057&itok=KGv_nwr-" alt="Avatar" class="image">
<div class="overlay">
<div class="img">
<img src="https://springhilles.fcps.edu/sites/default/files/styles/gallery/public/galleries/2022-08/IMG-2219.JPEG?h=d318f057&itok=kDKIfx7H" alt="Avatar" class="image">
</div>
</div>
</div>
</div>
<div class="column">
<div class="card">
<h3>Card 2</h3>
<p>Test text</p>
</div>
</div>
</div>
</body>
</html>