>我有一个固定宽度为 400px 的div。div 内有一个大于 400px 的表,所以我希望div 滚动。 这工作正常。 但我无法更改单元格的宽度。 我需要单元格 2 宽 200px。
<div style='width:400px;overflow:scroll'>
<table style='border:1px solid black'>
<th>field1</th>
<th style='width:200px'>field2</th>
<th>field3</th>
<th>field4</th>
<th>field5</th>
<th>field6</th>
<th>field7</th>
<th>field8</th>
<th>field9</th>
<th>field10</th>
<th>field11</th>
<th>field12</th>
<th>field13</th>
<th>field14</th>
<th>field15</th>
</table>
</div>
添加display: block
.如果希望表格单元格具有宽度,请从此解决方案中添加table-layout: fixed; width: 100%;
。不幸的是,这不适用于您的滚动功能。
<div style='width:400px;overflow:scroll'>
<table style='border:1px solid black'>
<th>field1</th>
<th style='width:200px; display: block;'>field2</th>
<th>field3</th>
<th>field4</th>
<th>field5</th>
<th>field6</th>
<th>field7</th>
<th>field8</th>
<th>field9</th>
<th>field10</th>
<th>field11</th>
<th>field12</th>
<th>field13</th>
<th>field14</th>
<th>field15</th>
</table>
</div>
将nowrap
属性添加到<th>
元素。有关nowrap
属性的详细信息
<div style="width: 400px; overflow: scroll">
<table style="border: 1px solid black">
<th>field1</th>
<th style="width: 200px" nowrap>field2</th>
<th>field3</th>
<th>field4</th>
<th>field5</th>
<th>field6</th>
<th>field7</th>
<th>field8</th>
<th>field9</th>
<th>field10</th>
<th>field11</th>
<th>field12</th>
<th>field13</th>
<th>field14</th>
<th>field15</th>
</table>
</div>