My main question is how to make 2 elements appear when hovering on an image.
Code produces:
The blue div is covering more space than it's half of 2 columns on hover. I think its because the span is taking up space on static not hover mode. Also, span is not horizontally centered inside the blue div despite the align-items:center on the container div.
.main {
margin: 50px;
width: 100%;
height: 800px;
background-color: red;
}
.wrapper {
margin: 15px;
}
.row {
display: flex;
flex-direction: row;
width: 100%;
gap: 15px;
}
.column {
display: flex;
flex-direction: column;
flex-basis: 100%;
flex: 1;
gap: 15px;
}
.rollover {
background-color: white;
}
.layer {
background-color: white;
font-family: Georgia;
color: white;
display: flex;
justify-content: center;
align-items: center;
}
.rollover:hover .layer {
visibility: visible;
background-color: blue;
height: 100%;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.layer span {
display: none;
color: black;
}
.layer:hover span {
display: inline;
font-size: 36px;
font-family: Georgia;
color: white;
z-index: 100;
}
.rollover:hover img {
visibility: hidden;
}
<body>
<div class="main"></div>
<div class="wrapper">
<div class="row">
<div class="column rollover">
<div class="layer"><img src="https://img.creator-prod.zmags.com/assets/images/648afc28b6fc7c5ba75cf2ab.jpeg?im=Resize,width=768"><span>The Alex</span></div>
</div>
<div class="column"><img src="https://img.creator-prod.zmags.com/assets/images/648afc28b6fc7c5ba75cf2ab.jpeg?im=Resize,width=768"></div>
</div>
</div>
</body>
I assume you want the two elements at same place so we can use a grid then put them both at that same row/column 1.
Reset to some basics at first.
Remove a bit of CSS.