In my code, I have created a 'img-cell' div that is empty but has a set height and background image. Beneath it, there is a 'text-cell' div with 100% width. (I have removed the PHP code from this example as it does not impact the layout)
The HTML structure looks like this:
<article>
<div class="img-cell">
</div>
<div class="text-cell">
<div class="extra-css" >
<h1>Title</h1>
<h3>Category</h3>
</div>
</div>
</article>
For the CSS styling:
article {
position: relative;
margin: 0;
padding: 0;
}
.img-cell {
position: relative;
height: 375px;
width: auto;
padding: 0;
margin: 0;
border-top: 1px solid #000;
background-size: cover;
background-repeat: no-repeat;
}
.text-cell {
position: absolute;
z-index: 10;
padding: 15px 0;
width: 100%;
margin: auto;
top: 0;
bottom: 0;
display:table;
}
Currently, the 'text-cell' div is vertically centered over the 'image-cell' div only in Safari browser, not in Firefox or other browsers due to the use of display:table. I am looking for an alternative solution to achieve the vertical centering without using tables.
EDIT - On mobile screens, I change the positioning of 'text-cell' to relative so it appears below the 'img-cell' div.