【问题标题】:offsetWidth vs scrollWidth: should be different, but the sameoffsetWidth vs scrollWidth:应该不同,但相同
【发布时间】:2017-06-19 20:51:59
【问题描述】:

我看过: Understanding offsetWidth, clientWidth, scrollWidth and -Height, respectively

但事实并非如此。例如,

.main {
   width: 400px;
   overflow: visible;
}

.main table {
  width: 600px;
}

<div class="main">

     <table>
         <thead><tr><th>Foo</th><th>Bar</th></tr></thead>
         <tbody>
              <tr><td>Row1</td><td>Hello</td></tr>
              <tr><td>Row2</td><td>World</td></tr>
         </tbody>

     </table>

</div>


---------------------------------------
|main                                 |
|      ----------------------------------------------------
|      | table                                            |
|      ----------------------------------------------------
|                                     |
|                                     |
---------------------------------------

主div元素的offsetWidth和scrollWidth都是一样的:400,应该分别是400和600吧?

【问题讨论】:

    标签: css html scroll width offsetwidth


    【解决方案1】:

    似乎在为我工作?

    http://codepen.io/anon/pen/EZEzGB

    alert("Scrollwidth: " + document.getElementById('main').scrollWidth + "OffsetWidth: " + document.getElementById('main').offsetWidth);
    

    你在用什么返回错误的值?

    【讨论】:

      猜你喜欢
      • 2021-01-26
      • 2014-01-30
      • 2015-01-09
      • 2015-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-11
      相关资源
      最近更新 更多