<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="shortcut icon" href="img/mynote.ico"/>
<title>position定位</title>
<style type="text/css">
div {
width: 200px;
height: 200px;
margin: 5px;
border: 1px solid black;
background: greenyellow;
text-align: center;
line-height: 200px;
}
#div1 {
/*固定位置,不改变*/
position: fixed;
top: 300px;
left: 300px;
}
#div2 {
/*绝对位置,相对于第一个父元素进行定位
一般用在具有相对定位的元素内部*/
position: absolute;
top: 0px;
left: 0px;
}
#div3 {
/*相对位置,相对于其正常位置进行定位*/
width: 200px;
height: 30px;
line-height: 30px;
position: relative;
top: 0px;
left: 0px;
}
</style>
</head>
<body>
<div id="div1">固定位置</div>
<div id="div2">相对位置</div>
<div id="div3">绝对位置</div>
</body>
</html>