CSS:设置表格的最大宽度

发布于 2024-12-20 23:18:24 字数 971 浏览 1 评论 0原文

我正在生成 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

陌上芳菲 2024-12-27 23:18:24

这行得通吗?这似乎适用于 jsfiddle。基于百分比的前两列,然后是第三列的宽度自动,带有表格布局:固定在表格上。

http://jsfiddle.net/keithwyland/uuF9k/1/

.actions {
  width:100%;
  table-layout: fixed;
}

.actions tr td {
  white-space: nowrap;
  width: 15%;
}

.actions tr td:nth-child(3) {
  white-space: normal;   
  word-break: break-all;
  word-wrap: break-word;
  width: auto;
}

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/

.actions {
  width:100%;
  table-layout: fixed;
}

.actions tr td {
  white-space: nowrap;
  width: 15%;
}

.actions tr td:nth-child(3) {
  white-space: normal;   
  word-break: break-all;
  word-wrap: break-word;
  width: auto;
}
冬天的雪花 2024-12-27 23:18:24

使用这个CSS

.actions {
width:100%;
}
.actions tr td:nth-child(3) {
 width:200px;
 word-wrap:break-word;
  display:inline-block;
}

use this css

.actions {
width:100%;
}
.actions tr td:nth-child(3) {
 width:200px;
 word-wrap:break-word;
  display:inline-block;
}
南…巷孤猫 2024-12-27 23:18:24

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.

╭ゆ眷念 2024-12-27 23:18:24

尝试输入 width: auto;。这将告诉浏览器使用所需的空间......

Try putting width: auto;. This will tell to the browser to use the needed space...

会发光的星星闪亮亮i 2024-12-27 23:18:24

这应该有效:

    .actions tr td:nth-child(3) {
         white-space: normal;
         word-break: break-all;
         max-width:200px;
     }

this should work:

    .actions tr td:nth-child(3) {
         white-space: normal;
         word-break: break-all;
         max-width:200px;
     }
故事与诗 2024-12-27 23:18:24

下面的 CSS 似乎让它对我有用。请注意添加了 table-layout:fixed,并使用了 word-wrap:break-word。

.actions {
    width:100%;
    table-layout:fixed;
}

.actions tr td {
    white-space: nowrap;
}

.actions tr td:nth-child(3) {
    white-space:normal;
    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.

.actions {
    width:100%;
    table-layout:fixed;
}

.actions tr td {
    white-space: nowrap;
}

.actions tr td:nth-child(3) {
    white-space:normal;
    word-wrap: break-word;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文