<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <script src="./js/jquery.min.js"></script> <style> .father { width: 200px; height: 200px; background-color: pink; margin-left: 100px; margin-top: 100px; position: relative; } .son { width: 100px; height: 100px; background-color: red; } </style> </head> <body> <div class="father"> <div class="son"></div> </div> <script> $(function() { //width 不受父级别影响 console.log($(".son").offset()); console.log($(".son").offset().top); //设置 $(".son").offset({ top: 200, left: 200 }) //只能获取 不能赋值 console.log($(".son").position()) }) </script> </body> </html>