How to center div (Note that table can be considered a div) __div

Source: Internet
Author: User
1: How to align the div to the center of its parent tag
Answer: First of all, we have to define a width for this div, then margin:0 Auto; <div style= "width:960px;margin:0 Auto" >
2: Today accidentally found align and text-align, want to take a good look at the next one of their differences.
1.align: Specify the horizontal alignment of the content in the DIV element.
2.text-align: Specify the horizontal alignment of the text in "element".

Two properties are not used in the same place, but they work the same. Align is relatively "narrow", such as:

Align (align is the attribute of the DIV):

<div align= "Center" > This is some text!
</div>
Text-align (Text-align is the property of CSS):

<div style= "Text-align:center" >

Both can make the content of the div centered, it's best to try it yourself,


3: Do the test in 2 and find a problem

<TD align= ' center ' >

<table><tr><td></td></tr></table>

</td>

<TD style= ' Text-align:center ' >

<table><tr><td></td></tr></table>

</td>

The above two ways can not make the table in the TD Center alignment, because the align is almost abandoned, now the browser almost do not support this property,

The text-align:center can only align the contents of the elements, not the elements inside the element (equivalent to text only)


4: How to solve the problem of 3.

You have to start with the table element itself,

<TD >

<table style= ' margin:0px auto ' ><tr><td></td></tr></table>

</td> done.

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.