static
默认的定位方式
实例:
<!DOCTYPE html>
<html>
<head>
<title>position.html</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="ex2.css" type="text/css"></link>
</head>
<body>
<div class="box">一</div>
<div id="move" class="box">二</div>
<div class="box">三</div>
</body>
</html>
.box{
width: 300px;
height: 200px;
background-color: gray;
border: 2px solid black;
/*float: left; */
margin-left: 10px;
}
relative
相对定位
.box{
width: 300px;
height: 200px;
background-color: gray;
border: 2px solid black;
float: left;
margin-left: 10px;
}
#move{
position: relative;/*相对定位,left意思是在原来的位置向左移动,但会保留原来的位置*/
left: 40px;
top: 100px;
}
absolute
绝对定位
.box{
width: 300px;
height: 200px;
background-color: gray;
border: 2px solid black;
float: left;
margin-left: 10px;
}
#move{
position: absolute;
left: 40px;
top: 100px;
}
相关文章推荐: