CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2001
    Location
    Indianapolis, IN
    Posts
    46

    Fixed column width in HTML tables

    Does anyone know how to fix the width of a <td> object in an HTML table? For example, I have a 5 column table. In the first row is a text string of variable length that spans all five columns. There are 5 more rows underneath that. I want the first 4 columns of the table to be a specific width, while allowing the 5th column to grow as necessary to fill out the row given the length of the row. Does anyone have any ideas (preferably a tag parameter that I'm unaware of)? I'm trying to keep a set of images specifically lined up in the first four columns and keep getting stung when the columns widen up to accomodate long strings in the first row.

    Thanks,
    Matt

  2. #2
    Join Date
    Jan 2003
    Location
    North Carolina
    Posts
    309
    Either use the WIDTH=n paramter or STYLE="WIDTH:nxx" in a row after the varying row in each column to set size or do in all rows.

    Ex.

    Code:
    <table border=2 width="100%">
    	<tr>
    		<td colspan=5 style="text-align:center">Test</td>
    	<tr>
    		<td style="width:5pc">a</td>
    		<td style="width:5pc">&nbsp;</td>
    		<td style="width:5pc">&nbsp;</td>
    		<td style="width:5pc">you do have to do for at least one row.</td>
    		<td<Not tied to a fixed width except due to tables width set.<td>		
    	</tr>
    	<tr>
    		<td>a</td>
    		<td>&nbsp;</td>
    		<td>&nbsp;</td>
    		<td>&nbsp;</td>
    		<td>You don't have to do the width for every row.</td>		
    	</tr>
    </table>
    I suggest personally using a STYLE and attch to a Cascading Style Sheet to make more flexible and fit into the character of your overall site.

    Look at DHTML Objects on MSDN website and you can get more details as to the other length options. 5pc the pc means percent but there are others you can use.

  3. #3
    Join Date
    Feb 2003
    Posts
    5
    Nice reply, but I do want to correct one thing. In CSS (cascading style sheets), "pc" means picas (an old typographic unit of measure, little used on the web). To make percent, you use %.

    Larry

  4. #4
    Join Date
    Jan 2003
    Location
    North Carolina
    Posts
    309
    Thanks, was typing and thinking at the same time. You know how that goes. Also fix typo

    <td<Not tied to a fixed width except due to tables width set.<td>

    to

    <td>Not tied to a fixed width except due to tables width set.<td>
    ___^

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured