简体   繁体   English

具有可变列的固定宽度表

[英]Fixed width table with variable columns

I've got a fixed width table ( style="width: 100%" ) with dynamic data being placed into the cells. 我有一个固定的宽度表( style="width: 100%" ),并将动态数据放入单元格中。 The data varies greatly in terms of width, and some strings exceed the length of the table without spaces. 数据的宽度差异很大,有些字符串超出了表的长度而没有空格。 Therefore, I've used table { table-layout:fixed; word-wrap: break-word; } 因此,我使用了table { table-layout:fixed; word-wrap: break-word; } table { table-layout:fixed; word-wrap: break-word; } table { table-layout:fixed; word-wrap: break-word; } to wrap the text in the columns, and keep the table from exceeding the page width. table { table-layout:fixed; word-wrap: break-word; }将文本包装在各列中,并防止表格超出页面宽度。

However, this results in equally spaced columns, which is not an optimal use of the space of my table, resulting in some cells that are wrapped two or three times, and others that have one word in all that space. 但是,这导致列之间的间距相等,这并不是对表空间的最佳利用,导致某些单元格被包装了两到三次,而另一些单元格在所有空间中只有一个单词。

Is there a way to keep a maximum table width, break words, and utilize the browsers layout optimizations for variable width columns? 有没有办法保持最大的表宽度,断词,并利用浏览器的可变宽度列布局优化?

If you have a column that you always expect to be larger than the others, you should indicate with eg <td width="40%"> . 如果您一直希望自己的列要比其他列大,则应使用<td width="40%">指示。 Also, if there is a column which will always be small, you can set a width to that as well. 另外,如果有一列总是很小,那么您也可以为其设置宽度。 The more clues you give the browser, the better the layout will look. 您给浏览器提供的线索越多,布局看起来就越好。

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

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