Friday, 6 July 2012

CENTER ALIGNING BY MARGIN PROPERTY


Center Aligning Using the margin Property

Block elements can be aligned by setting the left and right margins to "auto".

HINT: Using margin:auto will not work in IE8 and earlier, unless a !DOCTYPE is declared.

Setting the left and right margins to auto specifies that they should split the available margin equally. The result is a centered element:


Example

.center
{
margin-left:auto;
margin-right:auto;
width:70%;
background-color:#b0e0e6;
}

No comments:

Post a Comment