The absolute centering technique of 8 kinds of CSS to achieve vertical center horizontal Center

Source: Internet
Author: User

1. Absolute centering (Absolute centering) technology

We often use margin:0 auto, to achieve horizontal center, and always think Margin:auto; not vertical center ... In fact, implementing vertical centering requires only declaring the element height and the following CSS:

. absolute-center {   margin:auto;   Position:absolute;           Left:  0; right:0;  Top:  0; bottom:0;}

Advantages:

1. Support cross-browser, including Ie8-ie10;

2. No additional special tags, the amount of CSS code is small;

3. Support percent% attribute value and Min-/max attribute;

4. Use only this class to achieve the center of any content block;

5. Whether or not the set padding can be centered (without using the box-sizing attribute);

6. Content blocks can be redrawn;

7. Perfect support for image centering.

Disadvantages:

1. Height must be declared (see variable height Variable);

2. Easy to set Overflow:auto, to prevent the content of the monthly overflow. (View overflow overflow)

3. Not working on Windows Phone devices

Browser compatibility:

Chrome,firefox,safari,mobile Safari,ie8-ie10,

The absolute positioning method is tested on the latest version of Chrome,firefox,safari,mobile Safari,ie8-ie10.

The absolute centering technique of 8 kinds of CSS to achieve vertical center horizontal Center

Related Article

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.