css水平对齐

使用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;

}

猜你喜欢

转载自blog.csdn.net/weixin_41060905/article/details/81181704