How to center a page in a Web page made by Div+css

Source: Internet
Author: User
Tags relative

I write the page is wrapped in a div called #container, so here is mainly about the relationship between body and #container.

First look at the body's CSS style:

body{Margin:0;padding:0;text-align:center;}

Here the body put margin and padding set to 0, so that the body content with the edge of the browser close contact. Then text-align:center the contents of the body all centered, so that includes the #container also centered together.

Let's look at the style of #container:

Container{width:760px;margin:0 auto;text-align:left;position:relative;}

Learning is in this #container: Set the width of the container, here is the 760px,margin:0 auto; Here the first 0 of the margin is up and down, and the second auto is around. Up and down for about 0 let its self-control. Plus positioning as relative, only the relative elements can be positioned to move!

Related Article

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.