views:

99

answers:

3

I'm having trouble getting a td to have some text at its top and an image button on its bottom. Here is code similar what I have now:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html>
<head></head>
<body>
<table border="1">
  <tr>
    <td valign="top" style="padding:0; height:100%">
      Some text
      <form style="vertical-align: bottom;">
        <input type="submit" value="should be at bottom of td"/>
      </form>
    </td>
    <td>
      This <br />
      This <br />
      This <br />
      This <br />
      This <br />
      This <br />
      This <br />
      This <br />
      This <br />
      This <br />
      This <br />
      This <br />
    </td>
  </tr>
</table>
</body>
</html>

Technically I can achieve what I want by splitting the first <td> into 2 rows and using rowspan="2" on the other <td>, but I would like to avoid that since it is un-intuitive and I consider it a hack. Also, I only need to support the lastest versions of FF and Chrome. Any ideas?

P/S: I am dealing with tabular data here so please no "you shouldn't be using tables!" kind of advice.

UPDATE: Added DocType and browser support requirements.

+1  A: 

Not sure if it's the best way, but this should work.

<html>  
<head></head>  
<body>  
<table border="1">  
  <tr>  
    <td style="padding:0;height:100%;">  
      <table style="height:100%;">
        <tr>
            <td style="vertical-align:top;">        
                <p style="vertical-align: top;">Some text</p> 
            </td>
        </tr>
        <tr>
            <td style="vertical-align:bottom;">
                <form>  
                  <input type="submit" value="should be at bottom of td"/>  
                </form> 
            </td>
        </tr>
      </table> 
    </td>  
    <td>  
      This <br />  
      This <br />  
      This <br />  
      This <br />  
      This <br />  
      This <br />  
      This <br />  
      This <br />  
      This <br />  
      This <br />  
      This <br />  
      This <br />  
      This <br />   
    </td>  
  </tr>  
</table>  
</body>  
</html>  
Matt
Thanks Matt, but this breaks when there are multiple rows where the 2nd `<td>` is of varying height.
Suan
Updated try that.
Matt
Unfortunately this breaks in Chrome too, even if I set the height on the `<tr>s`
Suan
A: 

You should be able to use CSS positioning. Try this, but use a CSS stylesheet of course :-)

<td style="height:100%">
   <div style="position:relative;height:100%;">
      <p>Some text</p>
      <form style="position:absolute;bottom:0;">...</form>
   </div>
</td>

Note that you need to place a div inside of the td because the position attribute wont work within the td

BIGDeutsch
@BIGDeutsch: Your solution works and is a good solution. However, it doesn't work with the DOCTYPE my team is using: XHTML 1.0 Transitional. I've even validated the page, but what happens is that the `<div>` never stretches to fit the height of the `<td>`, so all the content stays in the vertical middle. Any ideas to make this work in XHTML?
Suan
Another update: Turns out that the XHTML Doctype wasn't the exact problem. The problem is that this solution only works with _no_ Doctype (ie Quirksmode). As before, hopefully somebody has other ideas while I investigate further - I would hate to think that this can't be done!
Suan
Try adding a height of 100% to the tr?
BIGDeutsch
Wow why didn't I think of that? Still, unfortunately it only works on Firefox and not Chrome...
Suan
+1  A: 

Finally found out how to do it. The key was to set the height of the <table> to 100%. I also removed the <p> around the top-aligned text.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;

<head>
  <title></title>
</head>

<body>

<table border="1" style="height: 100%;">
  <tr>
<td style="height:100%;">
   <div style="position:relative;height:100%; margin:0; padding:0;">
      Some text
      <form style="position:absolute;bottom:0px; margin:0; padding:0;">...</form>
   </div>
</td>
    <td>
      This <br />
      This <br />
      This <br />
      This <br />
      This <br />
      This <br />
      This <br />
      This <br />
    </td>
  </tr>
</table>

</body>
</html>
Suan