Of course, I donβt want to add CSS issues to the bunch of vertical alignments, but I spent hours trying to find a solution until it helped. Here's the situation:
I am creating a slideshow image gallery. I want the images to be displayed as strongly as the user window allows. So, I have this external placeholder:
<section class="photo full">
(Yes, I use HTML5 elements). Which has the following CSS:
section.photo.full { display:inline-block; width:100%; height:100%; position:absolute; overflow:hidden; text-align:center; }
Then the image is placed inside it. Depending on the orientation of the image, I set either the width or the height to 75%, and the other axis is auto:
$wide = $bigimage['width'] >= $bigimage['height'] ? true: false; ?> <img src="<?= $bigimage['url'] ?>" width="<?= $wide? "75%" : "auto"?>" height="<?= $wide? "auto" : "75%"?>"/>
So, we have a liquid outer container, inside of which is a liquid image. Horizontal centering the image works, but I can't find a way to vertically center the image inside the container. I researched centering methods, but most assume the container or image has a known width or height. Then there is the display: the table-cell method, which doesn't seem to work for me either.
I am stuck. I am looking for a CSS solution, but I am also open to js solutions.
Ferdy source share