1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> *{ margin: 0; padding: 0; } .box{ width: 300px; height: 300px; margin: 50px; background-color: skyblue; border: 5px solid gold; padding: 20px; } .one{ width: 200px; height: 200px; background-color: gray; } </style> </head> <body> <div class="box"> <div class="one"> </div> </div> </body> </html> <script type="text/javascript"> var box =document.querySelector(".box"); var one=box.firstElementChild;
console.log("内尺寸:",box.clientWidth,box.clientHeight); console.log("外尺寸:",box.offsetWidth,box.offsetHeight);
console.log(box.offsetLeft); console.log(box.offsetTop); console.log("测试one"); console.log(one.offsetLeft); console.log(one.offsetTop); console.log(one.offsetParent);
console.log("box:",box.clientLeft,box.clientTop); console.log("one:",one.clientLeft,one.clientTop); </script>
|