Three ways to center a CSS div

Source: Internet
Author: User

The first method margin method, the original code as shown in the figure.

#nei的margin的左右上下的边距. Get the center effect.

The second method. Pisition method, the location of the center is computed by absolute positioning, the code is as follows.

The third method. Span method, set a span that is not displayed in the page, set it to the height of the inline-box,span at the same time as the element to be centered, automatically extend to the height of parent 100%, and set two inline block elements to be centered vertically, so that the element can be centered. The specific code is as follows

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.