相对定位
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> </head> <style> #div1 { width: 1000px; height: 500px; border: 1px black solid; } #div2 { width: 100px; height: 100px; background-color: aqua; } #div3 { width: 100px; height: 100px; background-color: rebeccapurple; position: relative; top: 10px; left: 10px; } </style> <body> <div id="div1"> <div id="div2">我是div</div> <div id="div3">我是相对定位</div> </div> </body>

相对定位
设置为相对定位的元素框会偏移某个距离。元素仍然保持其未定位前的形状,它原本所占的空间仍保留

浙公网安备 33010602011771号