There are a number of ways to center vertically, and here's a quick and easy way to record what I've found.
A parent div and a sub-div need to be specified, and the sub-div will be vertically centered in the parent Div, then the content you want to center vertically is placed in the sub-div.
Chrome, Firefox, and IE are all available. IE only tested the edge and IE11.
1 <HTML>2 3 <Head>4 <style>5 . Vcenter-outter{6 Display:Table;7 background:Green;8 width:100%;9 Min-height:300px;Ten } One A . Vcenter-inner{ - Display:Table-cell; - text-align:Center; the vertical-align:Middle; - } - - . Vcenter-inner span{ + background:Red; - width:33%; + Height:Auto; A } at </style> - </Head> - - <Body> - <Divclass= "Vcenter-outter"> - <Divclass= "Vcenter-inner"> in <span>Center vertically</span> - </Div> to </Div> + </Body> - the </HTML>
The advantage of this approach is that if you have several different types of elements that you want to center vertically on the same line, you can use a parent div to cover multiple sub-div.
1 <HTML>2 3 <Head>4 <style>5 . Vcenter-outter{6 Display:Table;7 background:Green;8 width:100%;9 Min-height:300px;Ten } One A . Vcenter-inner{ - Display:Table-cell; - text-align:Center; the vertical-align:Middle; - } - - . Vcenter-inner span{ + background:Red; - width:33%; + Height:Auto; A } at </style> - </Head> - - <Body> - <Divclass= "Vcenter-outter"> - <Divclass= "Vcenter-inner"> in <span>Vertically centered span</span> - </Div> to <Divclass= "Vcenter-inner"> + <ul> - <Li>Vertically centered UL</Li> the <Li>Vertically centered UL</Li> * <Li>Vertically centered UL</Li> $ <Li>Vertically centered UL</Li>Panax Notoginseng </ul> - </Div> the <Divclass= "Vcenter-inner"> + <img>Vertically centered img</img> A </Div> the </Div> + </Body> - $ </HTML>
Reference article: http://www.htmleaf.com/ziliaoku/qianduanjiaocheng/201505121820.html
CSS for vertical centering