CSS webpage layout tutorial 3: fixed width center in one column

Source: Internet
Author: User

The center of the page is the most common form of webpage design. In the traditional table layout, we use the table's align = "center" attribute ,. The DIV itself also supports the align = "center" attribute, which can also center the DIV, but the CSS layout is to achieve separation of performance and content, while the align attribute is a style Code , Written in the DIV attribute of XHTML, there is a violation of the sharing principle (separation can make your website more conducive to management), so the CSS method should be used to center the content, take the layout code of a fixed-width column as an example to add a CSS style centered on it:

Copy code The Code is as follows: # layout {
Border: 2px solid # a9c9e2;
Background-color: # e8f5fe;
Height: 200px;
Width: 300px;
Margin: 0px auto;
}

The margin attribute is used to control the margin of the object in the top, right, bottom, and left directions. When margin uses two parameters, the first parameter indicates the top and bottom margins, and the second parameter indicates the left and right margins. In addition to using values directly, margin does not support auto. The auto value allows the browser to automatically determine the margins. Here, we set the left and right margins of the current Div to auto, the browser will set the left and right margins of the DIV to the same and display them as the center, thus achieving the effect in the game.
Note: This method is not supported by browsers earlier than IE6, And the CSS hack section below describes the solution in detail.Xmlns = "http://www.w3.org/1999/xhtml">


Center a column with fixed width (aa25.cn)

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.