CSS:设置表格的最大宽度
我正在生成 html 格式的应用程序日志,并且偶然发现了一个相当烦人的问题。我有以下布局:
| Action | Result | File path |
例如,
| Copy | Success | C:\VeryVeryVeryLongF |
| | | ileName.txt |
第 1 列和第 2 列仅显示短标签:它们的内容应保留在一行上。另一方面,第 3 列可能包含非常长的文件路径,如果不能放在一行中,则应跨越多行。
为了实现这一点,我在第一列上使用了 white-space: nowrap;
,并在第一列上使用了 white-space: normal; word-break: break-all;
在最后。此外,表格的宽度为100%。
这在 Chrome 和 IE 中效果很好,但在 Firefox 中则不然:简而言之,我似乎找不到一种方法来告诉 Firefox 8.0 不要放大表格的最后一列,而是让文本跨越多行。在我之前的示例中,Firefox 打印的
| Copy | Success | C:\VeryVeryVeryLongFileName.txt |
前两列中的文本可能会有所不同,因此我无法手动设置它们的宽度并使用 table-layout:fixed
。我还尝试在桌子上设置 max-width
并将其包装在 div
中,但无济于事。
请参阅 http://jsfiddle.net/GQsFx/6/ 了解真实示例 =)如何让 Firefox 表现得像 Chrome 一样?
I'm generating application logs in html, and I've stumbled across a rather annoying problem. I have the following layout :
| Action | Result | File path |
For example
| Copy | Success | C:\VeryVeryVeryLongF |
| | | ileName.txt |
Columns 1 and 2 only display short labels : their contents should stay on one single line. On the other hand, column 3 may contain very long file paths, which should span multiple line if they can't fit on a single line.
To achieve this, I've used white-space: nowrap;
on the first columns, and white-space: normal; word-break: break-all;
on the last. Also, the table has width:100%
.
This works great in Chrome and IE, but not in Firefox : In short, I can't seem to find a way to tell Firefox 8.0 to not enlarge the last column of the table, and instead let the text span multiple lines. In my previous example, Firefox prints
| Copy | Success | C:\VeryVeryVeryLongFileName.txt |
The text in the first two columns may vary, so I can't set their width manually and use table-layout: fixed
. I've also tried setting max-width
on the table, and wrapping it in a div
, to no avail.
See http://jsfiddle.net/GQsFx/6/ for a real-life example =) How can I make Firefox behave like Chrome?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这行得通吗?这似乎适用于 jsfiddle。基于百分比的前两列,然后是第三列的宽度自动,带有表格布局:固定在表格上。
http://jsfiddle.net/keithwyland/uuF9k/1/
Will this work? This appears to work with the jsfiddle. Percentage based first two cols, then width auto the third, with table-layout: fixed on the table.
http://jsfiddle.net/keithwyland/uuF9k/1/
使用这个CSS
use this css
max-width 是有效的 CSS2,但仅在 NS7、Opera 7 和可能的 Mozilla 中受支持。我不相信 IE 6 不支持它。
max-width is valid CSS2 but only supported in NS7, Opera 7 and probably Mozilla. I don't believe it's supported in IE 6.
尝试输入
width: auto;
。这将告诉浏览器使用所需的空间......Try putting
width: auto;
. This will tell to the browser to use the needed space...这应该有效:
this should work:
下面的 CSS 似乎让它对我有用。请注意添加了 table-layout:fixed,并使用了 word-wrap:break-word。
The following CSS seems to get it to work for me. Note the addition of table-layout:fixed, and the use of word-wrap: break-word.