<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> *{ padding: 0; margin: 0; } .box{ width: 200px; height: 200px; border: 10px solid blue; padding: 10px; overflow: auto; } .inner{ width: 300px; height: 300px; } </style> </head> <body> <div id="box" class="box"><div class="inner"></div></div> <script> console.log(box.scrollWidth); console.log(box.scrollHeight); </script> </body> </html>
为何宽度计算,比高度要少算10px。
weibo_哆啦A梦有大口袋_0