Dimension-adaptive elements are centered vertically horizontally

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.