简体   繁体   English

宽度窄时如何告诉浏览器在正确的位置缩小表格单元格

[英]How to tell the browser to shrink the table cell at the right place when width is narrow

Confusing title, I know.令人困惑的标题,我知道。 If anyone has a suggestion that is more suitable please tell me.如果有人有更合适的建议,请告诉我。

I have a table which has a very long content in the second column and that makes the content of the last column overflow even though there is enough space in the second column because content gets wrapped.我有一个表,其中第二列的内容很长,即使第二列中有足够的空间,最后一列的内容也会溢出,因为内容被包装了。 How do I tell the browser to shrink the space of the second column instead of overflowing on the last one?如何告诉浏览器缩小第二列的空间而不是溢出最后一列?
I feel like this has something to do with padding.我觉得这与填充有关。

Here is my table and as you can see the right column is overflowing.这是我的桌子,你可以看到右栏溢出了。 最后一列突出显示的表格 Now I want the browser to remove space from the right of the second column (with the new place thanks to the word-wrap) first (dashed red), then from the padding (dashed blue) until suppressing the padding totally and after that not overflowing text but blocking the table width and not shrinking the table any more (like min-width does).现在我希望浏览器首先从第二列的右侧删除空间(由于自动换行,有了新的位置)(红色虚线),然后从填充(蓝色虚线)直到完全抑制填充,之后不溢出文本但阻止表格宽度并且不再缩小表格(就像 min-width 一样)。
There is a lot of blank space that can be removed before overflowing.在溢出之前可以删除很多空白空间。 第二列突出显示的表格 I want the table to be dynamic, and I need exactly the default behaviour except that it doesn't seem to be optimized for my specific use case.我希望表是动态的,并且我需要完全的默认行为,除了它似乎没有针对我的特定用例进行优化。

 table { width: 100%; border-collapse: collapse; } td, th { border: 1px solid black; padding: 10px 5%; } td:first-child, th:first-child { padding: 10px; }
 <table> <tr> <th>#</th> <th>Header 2</th> <th>Header 3</th> </tr> <tr> <td>10</td> <td>...\ErrorHandlerMiddleware->App\Application\Middleware\{closure}(...)</td> <td>...\HelloAction.php:42</td> </tr> <tr> <td>11</td> <td>...\MiddlewareDispatcher.php:128$25a->handle(...)</td> <td>...\ErrorHandlerMiddleware.php:91</td> </tr> </table>

You can either apply word-wrap: break-word;您可以应用word-wrap: break-word; to the td element or set a smaller, fixed padding到 td 元素或设置较小的固定padding

See the snippet below:请参阅下面的片段:

 table { width: 100%; border-collapse: collapse; } td, th { border: 1px solid black; } td:first-child, th:first-child { padding: 10px; } td { word-wrap: break-word; }
 <table> <tr> <th>#</th> <th>Header 2</th> <th>Header 3</th> </tr> <tr> <td>10</td> <td>...\ErrorHandlerMiddleware->App\Application\Middleware\{closure}(...)</td> <td>...\HelloAction.php:42</td> </tr> <tr> <td>11</td> <td>...\MiddlewareDispatcher.php:128$25a->handle(...)</td> <td>...\ErrorHandlerMiddleware.php:91</td> </tr> </table>

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

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