views:

700

answers:

1

Hi all,

Do you know, how to fix the size of a td Width and Height in a table allowing the rest of td on table to expand as needed?

Thanks.

The problem is that when there is data inside of td's it will not shrink more than the data, but if is empty it will shrink all the way, if you expand the window the td will expand.

I would like to keep the size of the td whether you expand or shrink the window and whether the td has data inside or not.

Also I need to keep the rest of td's able to expand as you expand window.

Class tableContainerRow2 is the one I need it to be a fixed size. e.g.

<style>
.divContainer

{
margin:10px; background-color:#C7D8EE; border:2px solid #0076BF; text-align:left;
}

.tableContainer

{ color:#0076BF; margin: -10px 0px -10px 0px; border-spacing: 10px; empty-cells:show; width:90%;

}           
.tableContainerRow2{
background-color:white;
border:2px solid #0076BF;

}

<div class="divContainer">
<table class="tableContainer" cellspacing="10px">
    <tr>
       <td width="18%" style="white-space:nowrap;" >NHS Number</td>
       <td width="17%">&#160;</td>
       <td width="10%"  style="white-space:nowrap;">Date of Visit</td>
       <td width="10%">&#160;</td>
       <td colspan="3" style="white-space:nowrap;">Care Time Started</td>
       <td width="4%">&#160;</td>
       <td width="5%">&#160;</td>
       <td width="25%" rowspan="2" style="font-weight:bold;vertical-align:middle;white-space:nowrap;">Tick when<br/> care starts</td>
       </tr>
           <tr >
     <td width="18%" class="tableContainerRow2">&#160;0123456789</td>
     <td width="17%">&#160;</td>
     <td width="10%" class="tableContainerRow2">&#160;12/12/09</td>
     <td width="10%">&#160;</td>
     <td width="5%" class="tableContainerRow2">&#160;12</td>
     <td width="1%" >&#160;:</td>
     <td width="5%" class="tableContainerRow2">&#160;10</td>                          
     <td width="4%">&#160;</td>
     <td width="5%">&#160;&#9745;</td>
     <td width="10%" >&#160;</td>
           </tr>
       </table>

+2  A: 

just set the width of the td/column you want to be fixed and the rest will expand.

<td width="200"></td>
spatel
Would be better (for some value of better) to use CSS, but the principle is the same: inline style, or id/class assigned to the element will all work.
Richard
Thanks for your comment, I guess me not pasting any code did not help, but this solution did not work, maybe its me doing something wrong.
Cesar Lopez
your table is pretty heavy with all the specified widths. try removing all the styling and start over from scratch. don't use row wrapping. just valign the header row cells and don't use the whitespace nowrap style.Instead of colspan="3", use another table so you can display the columns that align with the one using colspan="3".You are using percentages as well which is ok, but did you try setting the one you want fixed to a specific pixel width?Tables have always been a pain for me to format when things get complicated. Start removing stuff one at a time to debug them.
spatel
Thanks spatel for your reply.
Cesar Lopez