实例
<!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> .ads{ width:350px; height:280px; background-color: aquamarine; position:fixed; right:0px; bottom:0; } button{ float: right; margin-right: 10px; } </style> </head> <body> <div class="ads"> <button onclick="this.parentNode.style.display = 'none'">关闭</button> <h2> PHP中文网-固定定位广告位</h2> </div> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例
总结:
固定定位:position:fixed;
this.parentNode:选择自身的父节点