使用margin属性来水平对齐
即将左和右外边距设置为"auto"
ex.
.center
{
margin-lefr:auto;
margin-right:auto;
width:50px;
background-color:red;
}
$:如果宽度是100%则对齐没有效果。
使用position属性进行左和右的对齐(要使用绝对定位)
ex:
.right
{
position:absolute;
right:0px;
width:300px;
background-color:red;
}
这里用到绝对定位,结合right属性对齐进行右对齐。
$:注意:一定要用到绝对定位。
使用float属性来进行左和右对齐
ex:
.right
{
float:right;
width:300px;
background-color:red;
}