相對定位時,位置參照物難道不是元素本身嗎?
看這段代碼:
```
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.test1 {
width: 100px;
height: 100px;
background: red;
position: relative;
}
.test2 {
width: 100px;
height: 100px;
background: blue;
position: relative;
top: 100px;
left: 100px;
}
</style>
</head>
<body>
<div class="test1"></div>
<div class="test2"></div>
</body>
</html>
```
test1 相對于自己(原本位置是:0 0)向右向下偏移了 50px,test2 相對于自己(原本位置是:100px 0)向右向下偏移了 100px
2019-02-14
對的,是參照元素本省本身,他視頻里講的有點問題
2019-01-17
相對定位參照位置是元素本身,test2原位置為test1下方,因為規(guī)定了top及l(fā)eft,所以在原位置的基礎(chǔ)上向右移動了100px