CSS Horizontal centering mode

Source: Internet
Author: User

1. Text-align:center

This method is only suitable for inline elements or text in the block element is, the block element set this, then the elements of the text or inline elements are centered. Compatible with various browsers

<class= "Center1"> I am the Test text oh </div> <  class= "Center1"><span> I am Test label span  </span></div>
. center1{    text-align:center;}
2. margin:0 Auto

Margin:0 Auto; applies only to block elements, and is a block element to have a width, but it doesn't matter what label is placed in the block element. Compatible with various browsers

<class= "Center2"> I am a block element with width </div> 
. Center2 {    margin:0 Auto;     width:200px;     background: tan;}
3. display:table

This is a good way to use, but only compatible with ie8+ browser

<class= "Center3"> I am the div</div That tests the centered way display:table  >
. Center3 {    display: table;     margin:0 Auto;     background: springgreen;}

Sample code

CSS Horizontal centering mode

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.