Common methods for centering CSS elements

Source: Internet
Author: User

Only normal and absolutely positioned elements can be centered, and floating elements do not exist in the center.

1. Block-level element centering1) Common flow elements (position:static or position:relative)
    • Center horizontally: {margin:0 auto;}
2) Absolute positioning elements (Position:absolute or position:fixed)
    • Horizontal, Vertical Center: the element {margin:auto; top:0; bottom:0; left:0; right:0; Overflow:auto}, whose parent element {position:relative;}
2. Inline-level element centering
    • Center horizontally: set {text-align:center on its parent element;}
    • Vertical Center in line: {height:30px; line-height:30px;}

Common methods for centering CSS elements

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.