CSS常用操作-对齐

时间:2023-03-09 18:46:31
CSS常用操作-对齐

CSS常用操作-对齐

index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>对齐</title>
<link href="style8.css" type="text/css" rel="stylesheet">
</head>
<body>
<div class="div"> </div>
</body>
</html>

利用margin属性

css:

*{
margin:0px;
}
.div{
width:%;
height:1000px;
background-color: red;
margin-left:auto;
margin-right:auto;
}

利用position属性

css:

 *{
margin:0px;
}
.div{
width:%;
height:1000px;
background-color: red;
position:absolute;
right:0px;/*居右操作*/
}

利用float属性

css

*{
margin:0px;
}
.div{
width:%;
height:1000px;
background-color: red;
float:left;/*向左浮动,对齐*/
}