fixing table width

Discussion in 'HTML & Website Design' started by Cinta April, Apr 23, 2008.

  1. #1
    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?
     
    Cinta April, Apr 23, 2008 IP
  2. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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):
     
    wd_2k6, Apr 23, 2008 IP
  3. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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
     
    Stomme poes, Apr 23, 2008 IP