如何将表格列的宽度设置为固定值?
我现在面临一个相当困难的问题;非常感谢你的帮助。
我有一个包含 2 列 td1 和 td2 的表格,其中包含文本,并且两者都有固定的宽度。
td1.width = 10px 和 td2.width = 20px
固定宽度是在运行时使用 JQuery 从左侧一一设置的(因为此表嵌套在另一个表中...)
文本宽度可能比这些固定宽度长在哪些情况下,预期的行为是
列的固定宽度应保持相同 1) 如果有额外的文本,文本应换行,不应增加或减少 td 宽度 2) 如果有空格,调整其他列或页面的大小时,不应减小单元格宽度;它应该保持完整。
我已将 td.whitespace 属性设置为 pre-wrap 和 td.word-wrap: break-word 但它们没有帮助。
使用 css 2.0(而不是 3.0)如何实现这些?
谢谢,
I'm facing a rather difficult issue at the moment; really appreciate your help.
I have a table with 2 columns, td1 and td2, and containing texts and both of which have fixed widths.
td1.width = 10px and td2.width = 20px
the fixed width are set at runtime one by one from the left using JQuery (as this table is nested inside another table...)
The text width may be longer than these fixed widths in which scenarios the expected behaviour is that
the fixed width of the columns should stay the same 1) if there are extra texts, the text should wrap, it should not increase or decrease the td width 2) if there are empty spaces, the cell width should not be reduced when resizing other columns or page; it should stay intact.
I have set the td.whitespace property to pre-wrap and td.word-wrap: break-word but they haven't helped.
how would these be possible using css 2.0 (not 3.0)?
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在这种情况下,由于宽度太小,并且文本通常不会有这么小的单词,因此它无法将它们换行,因此即使使用一组,它也会扩展
td
的宽度宽度!它减少了第二个 td 的宽度,因为第一个使用了额外的宽度。
另外,您可能会遇到文本太宽(例如很长的单词)的情况,在这种情况下无法将其换行。除非使用 javascript,我认为这是唯一的方法。
我建议阅读以下答案:HTML TD 换行文本
In this case, because the widths are so small, and the text doesn't typically have words that small, it has no way to wrap them, so it extends the width of the
td
even with a set width!It decreases the width of the second
td
because the first is using an extra width.Also, you could have a situation where the text is so wide (a long word for example) and in that case there is no way to wrap it. Unless using javascript, IMO it is the only way.
I recommend reading this answers: HTML TD wrap text
好的,我已经解决了。我的桌子上有 thead 和 colgroups。尽管它们的显示属性被隐藏,但 IE 9.0 会忽略它,而 IE 6.0 在计算列宽时会考虑它们!
我使用 jquery 删除了它们并进行了整理!
$('.myTable thead, .myTable colgroup').remove();
ok, I got it resolved. My table had thead and colgroups. Althought their display attribute was hidden, IE 9.0 ignores it whereas IE 6.0 takes them into account in calculating the width of columns!
I removed them using jquery and sorted out!
$('.myTable thead, .myTable colgroup').remove();