Vertical centering variable height image while maintaining max-width/height

This should prove to work quite well… no JavaScript necessary 🙂 See the working demo on jsFiddle. CSS /* Don’t Change – Positioning */ .absoluteCenter { margin:auto; position:absolute; top:0; bottom:0; left:0; right:0; } /* Sizing */ img.absoluteCenter { max-height:100%; max-width:100%; } HTML <img class=”absoluteCenter” src=”https://stackoverflow.com/questions/6282968/PATHTOIMAGE”> Note: This class can be used for anything quite easily. … Read more

Vertical align table-cell don’t work with position absolute

Everything works as expected until I add “position: absolute”. Now it can’t place my content in the middle any more? Why not? position: absolute forces display: block, read number two here. As for a workaround, I think you’ll have to wrap it in another element: <div class=”table-cell-wrapper”> <div class=”table-cell”> My text, should be align middle … Read more

How to center div vertically inside of absolutely positioned parent div

First of all note that vertical-align is only applicable to table cells and inline-level elements. There are couple of ways to achieve vertical alignments which may or may not meet your needs. However I’ll show you two methods from my favorites: 1. Using transform and top .valign { position: relative; top: 50%; transform: translateY(-50%); /* … Read more

Vertical-align image

This is pure CSS, vertically aligns the image, and also resizes the image down if it’s taller (or wider) than the containing box. Ergo, the box and image can both be any size without breaking the vertical alignment. Also, you may want to add a left margin to the <p> tags to keep them from … Read more