css - How to vertically center content with variable height within a div? -


what best way vertically center content of div when height of content variable. in particular case, height of container div fixed, great if there solution work in cases container has variable height well. also, love solution no, or little use of css hacks and/or non-semantic markup.

alt text

just add

position: relative; top: 50%; transform: translatey(-50%); 

to inner div.

what moving inner div's top border half height of outer div (top: 50%;) , inner div half height (transform: translatey(-50%)). work position: absolute or relative.

keep in mind transform , translate have vendor prefixes not included simplicity.

codepen: http://codepen.io/anon/pen/zyprdb


Comments

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -