admin管理员组文章数量:1389768
Screenshot
Important Note : This application does not support Internet Explorer. I will be happy with solution which will work in Chrome and Firefox.
I am using dynamic code (velocity-spring) for generating an html-table. Number of columns are not fixed (so I cannot specify width for headings). The second column values are always a link. Structure like this :
<table>
<tr>
<th ALIGN=CENTER> heading 1 </th>
<th ALIGN=CENTER> heading 2 </th>
... ... .... .. .. ..
<th ALIGN=CENTER> heading n </th>
</tr>
<tr ALIGN=CENTER>
<td ALIGN=CENTER> value 1 </td>
<td ALIGN=CENTER> <a href="mypage.html">value 2</a> </td> <!-- this column is a link -->
... ... .... .. .. ..
<td ALIGN=CENTER> value n </td>
</tr>
.... now more rows followed
</table>
Now problem is that if the second column (with hyperlink) contains a "loooooooooooooooooooooooong" value (without spaces) the other columns are wrapping their text. Please help me with css/jQuery/Javascript code, so that I maintain the structure of table with whatever values e from back-end.
UPDATE:
After getting answer, I updated my table code like below (as they say specify width
and use word-break
) :
<table>
<tr>
<th ALIGN=CENTER> heading 1 </th>
<th style="word-wrap:break-word; width: 200px;" ALIGN=CENTER> heading 2 </th>
... ... .... .. .. ..
<th ALIGN=CENTER> heading n </th>
</tr>
<tr ALIGN=CENTER>
<td ALIGN=CENTER> value 1 </td>
<td ALIGN=CENTER style="word-wrap:break-word; width: 200px;"> <a href="mypage.html">value 2</a> </td> <!-- this column is a link -->
... ... .... .. .. ..
<td ALIGN=CENTER> value n </td>
</tr>
.... now more rows followed
</table>
I know I need to accept and vote up usefull answers, doing. But please help me. I cant send you live URL. Attaching screen shots very soon.
Screenshot
Screenshot
Important Note : This application does not support Internet Explorer. I will be happy with solution which will work in Chrome and Firefox.
I am using dynamic code (velocity-spring) for generating an html-table. Number of columns are not fixed (so I cannot specify width for headings). The second column values are always a link. Structure like this :
<table>
<tr>
<th ALIGN=CENTER> heading 1 </th>
<th ALIGN=CENTER> heading 2 </th>
... ... .... .. .. ..
<th ALIGN=CENTER> heading n </th>
</tr>
<tr ALIGN=CENTER>
<td ALIGN=CENTER> value 1 </td>
<td ALIGN=CENTER> <a href="mypage.html">value 2</a> </td> <!-- this column is a link -->
... ... .... .. .. ..
<td ALIGN=CENTER> value n </td>
</tr>
.... now more rows followed
</table>
Now problem is that if the second column (with hyperlink) contains a "loooooooooooooooooooooooong" value (without spaces) the other columns are wrapping their text. Please help me with css/jQuery/Javascript code, so that I maintain the structure of table with whatever values e from back-end.
UPDATE:
After getting answer, I updated my table code like below (as they say specify width
and use word-break
) :
<table>
<tr>
<th ALIGN=CENTER> heading 1 </th>
<th style="word-wrap:break-word; width: 200px;" ALIGN=CENTER> heading 2 </th>
... ... .... .. .. ..
<th ALIGN=CENTER> heading n </th>
</tr>
<tr ALIGN=CENTER>
<td ALIGN=CENTER> value 1 </td>
<td ALIGN=CENTER style="word-wrap:break-word; width: 200px;"> <a href="mypage.html">value 2</a> </td> <!-- this column is a link -->
... ... .... .. .. ..
<td ALIGN=CENTER> value n </td>
</tr>
.... now more rows followed
</table>
I know I need to accept and vote up usefull answers, doing. But please help me. I cant send you live URL. Attaching screen shots very soon.
Screenshot
Share Improve this question edited Mar 26, 2012 at 9:48 buggy asked Mar 26, 2012 at 7:33 buggybuggy 451 silver badge7 bronze badges3 Answers
Reset to default 2word-wrap
will work but you need to specify a width
for the column.
Try to use the CSS attribute "word-wrap."
table td a
{
word-wrap: break-word;
}
This is supported in all major browsers and should fix your problem.
You can see a test case I created here. You don't need to specify a width for the element, it will work without (resize the result window to see.)
table td a {
// set a width
word-wrap: break-word
}
The 'word-wrap' solution only works in IE and browsers supporting CSS3.
The best cross browser solution is to use script language (javascript or whatever) to locate long strings and place inside them in regular intervals the html entity #8203; This entity breaks the long words nicely, and works on all browsers.
A nice regular expression should be:
"everyverylongword".replace(/([^\s-]{5})([^\s-]{5})/,"$1­$2")
本文标签: javascripttablecolumn is not wrapping textStack Overflow
版权声明:本文标题:javascript - table-column is not wrapping text - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744639226a2617017.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论