4 ms·
The table-cell solution for vertically centering text is incorrect. You need to put that display:table-cell div inside a display:table div. It requires the pare
by justindocanto 11y ago
The table-cell solution for vertically centering text is incorrect. You need to put that display:table-cell div inside a display:table div. It requires the parent in order to work properly.
Example: <div class="item"><div><p>Your text here</p></div></div>
.item {display:table;}
.item > div {display:table-cell;vertical-align:middle;}
I use this method on justindocanto.com to vertically center an unknown amount of text/elements inside a div that changes its size based on the size of the image that's inside it. Really nice technique when used correctly.
- scotty79 11y agoYes. This page gives wrong solutions for unknown size of centered block but known sizes of container.