How do I vertically align text in a colorbox?

Posted by Jennifer | Updated on

Want do I vertically align text in a colorbox? You can vertically center text by setting its line-height property to the height of the element it’s sitting in.

This trick will only work if you know the height of your div, of course. There are other methods, but they’re more complex.

Another method that isn’t linked is to set the div containing your text to position: relative;, then setting top to 50% minus the one half the height of the element. This is best done in Javascript.


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers