As I work on creating a stylish image viewer resembling a gallery, I'm determined to position the image at the center and middle of the page.
If the image is smaller than 100% of the page, achieving this alignment becomes as easy as using table
and table-row
. However, things get trickier when dealing with images that exceed this size. In such cases, my go-to approach involves utilizingtext-align: center
and max-height: 100%
.
To see how I implement this technique in action, check out my code here: https://jsfiddle.net/rtv393z7/
<div style="position: fixed; width: 100%; height: 100%; top: 0; left: 0; background-color: rgba(0,0,0,0.6);">
<div style="width: 100%; height: 100%; text-align: center;">
<img style="max-height: 100%; max-width: 100%; box-sizing: border-box; padding: 30px;" src="http://i.imgur.com/uRGZ0EE.jpg">
</div>
</div>
The challenge lies in getting this setup to function flawlessly in both scenarios. Any suggestions?