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.
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
Post a Comment