SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    574
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Freeze table headers, word-wrap width for columns

    Is there a way to freeze several rows at the top of an HTML table so that the data rows scroll up under the header? I've seen solutions where you set specific widths for each of the tds but I'm hoping to allow the data in the tds to word-wrap for the most part. I may set some widths where I know the dimension (like where there are tools with 16px icons), but the larger columns will need to word-wrap. It's a multi-column, potentially multi-row table. It will have to work across platforms and browser, ya-da, ya-da. I've seen solutions that "come close", i.e., column width might be between 2 and 12 px off depending on the browser, but I'd really like to nail it, if possible. Any way to do this?

  2. #2
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    936
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    I think for the headers you can use like this,

    Code:
    <table border="1">
      <tr>
        <th>Month</th>
        <th>Savings</th>
      </tr>
      <tr>
        <td>January</td>
        <td>$100</td>
      </tr>
    </table>
    Quality codes are optimized and tested...
    Click here for inspiration..

  3. #3
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,997
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Hi there,

    My first response would be to use a plugin.
    This one, for example, seems quite good: http://fixedheadertable.com/
    Is there a reason why this would not work?

  4. #4
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    40,478
    Mentioned
    182 Post(s)
    Tagged
    6 Thread(s)
    Hi,

    You can do something in CSS alone but there is limited styling capabilities of the fixed header due to the way it is moved.

    This is an old demo (as you can see by browsers supported).

    The effect is created by absolutely placing the table header content into some space at the top but the page is held open using a tfoot element to mirror the header instead.

    For anything more complicated you would need a script such as the one that Pullo mentions above.

  5. #5
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    574
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, Paul and Pullo. I'll check into both of these and be back if I have questions.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •