Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css offsetWidth vs scrollWidth:应该不同,但相同_Css_Html_Scroll_Width_Offsetwidth - Fatal编程技术网

Css offsetWidth vs scrollWidth:应该不同,但相同

Css offsetWidth vs scrollWidth:应该不同,但相同,css,html,scroll,width,offsetwidth,Css,Html,Scroll,Width,Offsetwidth,我看过: 但事实并非如此。比如说, .main { width: 400px; overflow: visible; } .main table { width: 600px; } <div class="main"> <table> <thead><tr><th>Foo</th><th>Bar</th></tr></thead&g

我看过:

但事实并非如此。比如说,

.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                                            |
|      ----------------------------------------------------
|                                     |
|                                     |
---------------------------------------
.main{
宽度:400px;
溢出:可见;
}
.主桌{
宽度:600px;
}
福巴
罗1你好
Row2World
---------------------------------------
|主要|
|      ----------------------------------------------------
||表|
|      ----------------------------------------------------
|                                     |
|                                     |
---------------------------------------

主div元素的offsetWidth和scrollWidth相同:400。它们应该分别是400和600,对吗

似乎在为我工作

您使用什么返回错误的值

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