Center Div with CSS

Source: Internet
Author: User

During webpage layout, text and images are usually centered for the sake of appearance. It is difficult to use Div to achieve the same effect after using table layout. In fact, it is not difficult for the meeting, as long as the following section Code You can easily center the DIV, and in the example, I have implemented two sidebar, which can basically meet the overall layout needs of most web pages. 1 <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
2 < Html Xmlns = "Http://www.w3.org/1999/xhtml" Dir = "LTR" >
3 < Head Profile = "Http://gmpg.org/xfn/11" >
4 </ Head >
5 < Body >
6 < Div Style = "Position: relative; margin-left: auto; margin-Right: auto; width: 786px; Background-color: Purple ;" >
7 < Div Style = "Width: 500px; float: Right" > Content </ Div >
8 < Div Style = "Background-color: yellow; width: 200px" > Sidebar </ Div >
9 < Div Style = "Background-color: Blue; width: 200px" > Sidebar </ Div >
10 </ Div >
11 </ Body >
12 </ Html >

Download code files

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.