.parent-element { -webkit-transform-style: preserve-3d; -moz-transform-style: preserve-3d; transform-style: preserve-3d; } .element { position: relative; top: 50%; -webkit-transform: translateY(-50%); -ms-transform: translateY(-50%); transform: translateY(-50%); }
参考:http://zerosixthree.se/vertical-align-anything-with-just-3-lines-of-css/
如果不行,请再参考:http://www.vanseodesign.com/css/vertical-centering/
评论