I have a challenge with aligning two div elements, each containing an image and a caption.
My goal is to center the images vertically within their respective divs without stretching or distorting them in any way.
Despite researching and trying various suggestions like the ones found on How TO - Center Elements Vertically and CSS Layout - Horizontal & Vertical Align, as well as seeking answers on Stack Overflow, none of the solutions have worked for me.
It's crucial that these elements are displayed responsively.
For testing purposes, I am using the following images:
.border_slide {
overflow: hidden;
}
.other_titles
{
margin-top: 5px;
height: 120px;
}
.other_titles div
{
width:49.5%;
margin-bottom: 5px;
}
.other_titles_cap
{
position: absolute;
z-index: 100;
width:100%;
background-color: rgba(69,69,69,0.4);
height: 70px;
margin-top: 80px;
transition: all 0.3s ease 0s;
}
/*.other_titles_cap:hover
{
margin-top: 0;
height: 150px;
}*/
.title2
{
height: 150px;
background-color: #9bfff0;
/*margin-left: 15px;*/
float: right;
}
.title2 img
{
margin-top: 0;
transition: all 0.4s ease 0s;
}
.title2:hover .other_titles_cap
{
margin-top: 0;
height: 150px;
}
.title2:hover img
{
width: 115% !important;
opacity: 0.8;
transform:translate(7%,-10%);
-ms-transform:translate(7%,-10%);
}
.title3
{
height: 150px;
background-color: #ffd5c4;
float: left;
}
.title3 img
{
-ms-transform:translate(7%,-10%);
margin-top: 0;
transition: all 0.4s ease 0s;
}
.title3:hover .other_titles_cap
{
margin-top: 0;
height: 150px;
}
.title3:hover img
{
width: 115% !important;
opacity: 0.8;
transform:translate(7%,-10%);
-ms-transform:translate(7%,-10%);
}
<div class="other_titles">
<div class="border_slide title2">
<div class="other_titles_cap">title of Post2</div>
<img class="" src="https://i.sstatic.net/k6HuQ.jpg" style="width:100%">
</div>
<div class="border_slide title3">
<div class="other_titles_cap">title of Post3</div>
<img class="" src="https://i.sstatic.net/90ten.jpg" style="width:100%">
</div>
</div>
I specifically require this functionality for responsive designs when the width is below 520px.
You can access the test environment here: