CSS 对齐操作

一:margin 水平对齐

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>margin 属性水平对齐操作</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" media="screen" href="main.css" />
    <script src="main.js"></script>
    <link rel="stylesheet" type="text/css" href="margin.css"/>
</head>
<body>
    <div class="div">
    </div>
</body>
</html>

CSS代码

* {
    margin: 0px;
}
.div {
    width: 70%;
    height: 950px;
    background-color: thistle;
    margin-left: auto;
    margin-right: auto;
}

 

 

二:position 左右对齐

/*右对齐*/
position: absolute;
right: 0px;

三:float 左右对齐

/*居左*/
float: left;
posted @ 2018-05-11 15:14  wuyueping  阅读(177)  评论(0编辑  收藏  举报