How do I get the div horizontally centered?

Source: Internet
Author: User

The 100 degree div is centered, most of it is an answer, but sometimes this method is not omnipotent ... No nonsense, will I know the methods are listed well, update at any time.

1, set the width value, specify margin-left and margin-right for auto (or margin:0 auto; (The way most people know, don't give an example)

2, set width, using Margin-left for the width of the negative half and relative positioning to achieve horizontal center (width and Margin-left can set the percentage)

1 #demo{2 width:500px;3 Height:300px;//height can not be set, use content to prop up height4 margin:0 0 0-250px;//(or directly set Margin-left:-250px;)5 position:relative;relative positioning6 Background-color:Pink;//easy to see effect7  Left:50%;8 Top:50%;9}
<id= "Demo"></div>

3. To be Continued ...

How do I get the div horizontally centered?

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.