如何使行的宽度适合表中其他行的宽度?
在下表中,第一个单元格内容是动态生成的。第二个单元格中的长文本会导致表格宽度超出适合第一个单元格所需的宽度。
如何让底部单元格换行到另一行,而不是加宽表格?
我无法对第二个单元格使用固定宽度,因为第一个单元格的内容直到运行时才知道。
<table border="1">
<tr><td>name: <input type="text"></input></td></tr>
<tr><td>blah blah blah blah blah blah blah blah blah blah</td></tr>
</table>
In the following table, the first cell content is dynamically generated. The long text in the second cell causes the table width to grow beyond what is needed to fit the first cell.
How can I get the bottom cell to wrap to another row, instead of widening the table?
I can't use a fixed width for the second cell, because the first cell content is not known until run time.
<table border="1">
<tr><td>name: <input type="text"></input></td></tr>
<tr><td>blah blah blah blah blah blah blah blah blah blah</td></tr>
</table>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我也希望有一个解决方案。其他问题的答案表明没有简单的答案...
HTML TD 换行文本
I too would have liked a solution to this. Answers to this other question indicates there is no easy answer...
HTML TD wrap text
不知道为什么你说不能使用固定宽度,因为你依赖于第一个单元格。您可以在运行时通过检查第二个单元格的值来计算此值,如果它比某个定义的宽度长,您将向单元格应用定义的宽度。
但是,如果第二个单元格的输出不是很长(并且不会触发您的长度检查),那么您不需要添加任何宽度定义。
这对我来说似乎很简单,但我的假设是您正在使用脚本语言来生成此内容,除非您的意思是这是纯 html,在这种情况下,我将使用像 jQuery 这样的 JS 库来解决问题并执行对值进行相同的长度检查,如果触发,则为单元格添加宽度定义。
Not sure why you say you cannot use a fixed width because you have a dependancy on the first cell. You can calculate this at run time by checking the value for the 2nd cell, and if it is longer than a certain defined width you would apply a defined width to your cell.
If the output for the 2nd cell however is not very long (and does not trigger your length check) then you do not need add any width definition.
It seems simple to me, but my assumption here is that you are using a scripting language on the side to generate this content, unless you mean this is PURE html, in which case I would tackle the problem with a JS library like jQuery and do the same length check on the value and if triggered add a width definition for your cell.
首先,不要像以前那样关闭输入,请执行以下操作:
第二:只需给表格固定宽度:
啊,最后第三:不要使用表格进行布局。即使没有表格也可以完成表格。
First of all, do not close you input like you do, do the following:
Second: Just give the table a fixed width:
Ah and finally third: Do not use tables for layouts. Even forms can be done without a table.