hi I want to fix my table width to 50% of the page. however my table contains text of variable length. if the text is long the table would stretch. how do i preventthis stretching and push the extra characters to the next line?
It should do if you have put it at 50% width. Here Check this example, no matter the length of the text it still goes onto the next line, the table width will always stick to 50%: <table width="50%"><tr><td>Short text</td><td>Longerrrrrrrrr Text</td><td>Even Longerrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr Texttttttttt</td><td>Short</td><td>Very Long Text Very Long Text Very Long Text Very Long Text Very Long Text Very Long Text Very Long Text Very Long Text Very Long Text Very Long Text Very Long Text</td></tr></table> Code (markup):
I sometimes found my content widening the table... but I had data tables, so there was a thead and th's inside... and when I set the width of the th's, then the rest of the columns generally complied. The exception was when the text in any data cell was a single, long word-- the table couldn't wrap a single word, so that whole column would get wider. No way around that that I know of. There's also a CSS used to make tables render faster, where the browser is told to make each row the same width after looking at the width of the cells in just that row: table-layout: fixed