简体   繁体   English

如何强制表格宽度等于其子td宽度并允许表格扩展到视口宽度之外

[英]How to force table width to equal to its child td width and allow table to extend beyond viewport width

I have a table with dynamic row + column. 我有一个带有动态行+列的表。

<table>
  <tr>
    <td>column 1</td>
    <td>column 2</td>
    <td>column 3</td>
  </tr>
  <tr>
    <td>11</td>
    <td>12</td>
    <td>13</td>
  </tr>
  <tr>
    <td>21</td>
    <td>22</td>
    <td>23</td>
  </tr>
</table>

I'd like to have the td width to always equal to its content. 我想让td宽度始终等于其内容。 At the moment, the table width expands according to the td width. 此刻,表格宽度根据td宽度扩展。 However, the total table width is constrained by the page width once the number of column increases. 但是,一旦列数增加,表的总宽度就受到页面宽度的限制。

I'm trying to find a way to maintain the auto td width but allow the table to expand beyond the page width. 我正在尝试找到一种方法来保持auto td宽度,但允许表扩展到页面宽度之外。 I attached a simple drawing of what I meant below: 我附上了我下面的意思的简单图纸:

在此处输入图片说明

Thanks in advance! 提前致谢!

Add this style: 添加此样式:

table {
  white-space: nowrap;  //prevent wrapping
}

Fiddle 小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM