绝对定位
<!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; } #div4 { width: 100px; height: 100px; background-color: pink; position: absolute; top: 100px; left: 100px; } </style> <body> <div id="div1"> <div id="div2">我是div</div> <div id="div3">我是相对定位</div> <div id="div4">我是绝对定位</div> </div> </body> </html>
绝对定位的框与文档流无关,所以它们可以覆盖页面上的其它元素。可以通过设置 z-index 属性来控制这些框的堆放次序。