<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>css相对定位</title>
<style>
#left,#center,#right{
float: left;
}
#left{
width: 200px;
height: 200px;
background-color: yellow;
}
#center{
width: 200px;
height: 200px;
background-color: #cccccc;
/*相对定位:相对于元素原来的的位置进行定位
元素原始的位置依然会保留,不会被其他元素占用*/
position: relative;
top: 20px;
left: 20px;
}
#right{
width: 200px;
height: 200px;
background-color: aquamarine;
}
</style>
</head>
<body>
<div>
<div id="left"></div>
<div id="center"></div>
<div id="right"></div>
</div>
</body>
</html>
当去除 #center中 position: relative;
top: 20px;
left: 20px;
结果为