CSS水平对齐,div居中对齐,左对齐,右对齐

我来纠错
//使用 margin 属性来水平对齐,将左和右外边距设置为 "auto",来对齐块元素。
把左和右外边距设置为 auto,规定的是均等地分配可用的外边距。结果就是居中的元素:
.center{ margin-left:auto; margin-right:auto; width:70%; background-color:#b0e0e6;}
提示:如果宽度是 100%,则对齐没有效果。

//使用  float 属性来进行左和右对齐:
.left{float:left;width:300px;background-color:#b0e0e6;}
.right{float:right;width:300px;background-color:#b0e0e6;}

//使用绝对定位 position 属性进行左和右对齐:
.left{ position:absolute; left:0px; width:300px; background-color:#b0e0e6; }
.right {position:absolute; right:0px; width:300px; background-color:#b0e0e6; }
发送
热门关键词:
命令
知识类型:
标题描述:
详细解答:

提交审核您编辑的知识会经过 前端大牛 人工审核。