About the center display of Div

Source: Internet
Author: User

Let a large div appear centered on the page:

The HTML code is as follows:

< Body >        <  ID= "container"></div></  Body>

Imperfect method:

1, only in the IE browser Center

<style type= "text/css" media= "screen" >
* {padding:0px;margin:0px; }

/**
* Centered in IE browser only
/Body{text-align:Center; }

#container{width:1100px;Height:500px;Border:1px solid #229; }</style>

2, outside the Internet Explorer, the other browser in the center

<style type= "text/css" media= "screen" > *{padding:0px;margin:0px; }#container{width:1100px;Height:500px;Border:1px solid #229;margin:Auto;/*in the browser outside of IE browser, to achieve the center*/}</style>

2. Center in all browsers

<style type= "text/css" media= "screen" > *{padding:0px;margin:0px; }#container{width:1100px;Height:500px;Border:1px solid #229;

/**
* The following three innings of code, to achieve the center of all browsers
/Position:Absolute; Left:50%;Margin-left:-550px; /* #container宽度的一半 */}</style>

About the center display of Div

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.