Dimension-adaptive elements are centered vertically horizontally:
If the size of the child element is fixed, then it is easier to set it to vertical horizontal centering, which is not introduced here, specifically, you can refer to the CSS implementation div Horizontal Vertical Center code chapter. If the dimensions of the child elements are not fixed, then setting them to center vertically is a bit cumbersome, as shown in the following code example:
<!DOCTYPE HTML><HTML><Head><MetaCharSet= "Utf-8"><Metaname= "Author"content= "http://www.51texiao.cn/" /><title>Ant Tribe</title><styletype= "Text/css">. Middle{Height:300px;width:300px;Border:1px solid;Display:Table-cell;text-align:Center;vertical-align:Middle;}. in{Background-color:Red;Height:Auto;width:Auto;Min-width:0px;Min-height:0px;Display:inline;}</style></Head><Body><Divclass= "Middle"> <Divclass= "in">Content Adaptive Horizontal Vertical centering</Div></Div></Body></HTML>
The code implements the functionality we want, but in the ointment is not compatible in the low version of IE browser, but over time, the low version of the browser after exiting the market can be a lot of use, of course, using JS to achieve compatible with all browsers, You can refer to the section that is compatible with all browsers for long-width adaptive element vertical horizontal centering.
The original address is: http://www.51texiao.cn/HTML5jiaocheng/2015/0521/2140.html
Dimension-adaptive elements are centered vertically horizontally