源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>编程字典</title> <style> div.relative { position: relative; width: 400px; height: 200px; border: 3px solid #73AD21; } div.absolute { position: absolute; top: 80px; right: 0; width: 200px; height: 100px; border: 3px solid #73AD21; } </style> </head> <body> <h2>position: absolute;</h2> <p>position: absolute; 位于相对就近父元素放置(而不是相对设置的视口,如:fixed):</p> <div class="relative">这个 div 元素 position: relative; <div class="absolute">这个 div 元素 position: absolute;</div> </div> </body> </html>
运行结果