Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto size header to fit table below 1

Status
Not open for further replies.

Glasgow

IS-IT--Management
Jul 30, 2001
1,669
GB
The HTML below is a cut-down version of a report template with a header block at the top followed by a table that, ultimately, will contain the report data. I want to ensure that the header automatically 'shrinks' to match the width of the table (rather than extend to full width of the window). I have tried using "width:auto" in various places to no avail.

Any help would be appreciated.

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
body                { font-family:verdana; font-size:7pt; }

</style>
<title>Title</title>
</head>

<body>

<div style="width:auto;background-color:yellow;">
  <div style="height:80px; border: solid 2px blue; background-color:lightgreen">
    <div style="height:50px; text-align:center">
      <p>Report Title</p>
    </div>
  </div>
  <table style="background-color:pink">
    <tr>
    <td>Column 01</td>
    <td>Column 02</td>
    <td>Column 03</td>
    <td>Column 04</td>
    <td>Column 05</td>
    <td>Column 06</td>
    <td>Column 07</td>
    <td>Column 08</td>
    </tr>
  </table>
</div>
</body>
</html>
 
If you float the div, it will assume auto width. I believe that is the only way of persuading a div to have an auto width across different browsers.

___________________________________________________________
[small]Do something about world cancer today: PACT[/small]
 
Thanks for the reply. To be honest, I'm still failing miserably even with floats. I think I will revert to a header that is contained in the first row of the table.
 
There is a <caption> tag which adds a caption to a table and the css can position it somewhere different other than above the table (where it would normally go). Otherwise, the <th> tag for the table header might work better for you.
I would be inclined to put all the formatting into a stylesheet, the Report Title as the table caption, and the column headings as th.
 
Thanks - I didn't know about the <caption> tag. That does the trick rather nicely.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top