源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>编程字典</title> <style> body { margin: 0; padding: 0; } .container { position: relative; width: 100%; } .right { position: absolute; right: 0px; width: 300px; background-color: #b0e0e6; } </style> </head> <body> <h2>右对齐</h2> <div class="container"> <div class="right"> <p><b>注意: </b>使用position属性对齐时, 总是包含!DOCTYPE声明! 如果缺少,它会在IE浏览器中产生奇怪的结果.</p> </div> </div> </body> </html>
运行结果