解决position:fiexd相对父元素定位
设置position:fiexd之后
不设置top,bottom,left,right位置样式,
通过margin间接调整
复制代码就是开干
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>Document</title> <style> .father { width:300px; height:300px; margin-top: 200px; margin-left: 200px; background:green; } .son { position:fixed; margin-top: 140px; width:150px; height:150px; background:red; word-break: break-all; } </style> </head> <body> <div class="father"> <div class="son"> son </div> </div> <p style="height:10000px"></p> </body> </html>