css元素的相对定位和绝对定位:
相对定位:当元素采用相对定位时,它会首先出现在原来的位置,然后通过top,left...等属性相对于原来的位置进行偏移,并且会占据原来的位置空间和偏移覆盖的空间。
绝对定位:当元素采用绝对定位时,元素会脱离文档流,既不会占据空间,然后通过top,left...等属性相对于离它最近并且采用相对定位的父级元素进行偏移。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>???????</title>
<style type="text/css">
.div1{
height:100px;
width:1000px;
background:red;
position:relative;
}
.div2{
height:50;
width:1000px;
background:red;
position:absolute;
margin-top:20px;
}
.div3{
height:200px;
width:1000px;
background:red;
position:absolute;
margin-top:80px;
}
</style>
</head>
<body>
<div class="div1">
</div>
<div class="div2">
</div>
<div class="div3">
</div>
</body>
</html>