Entry
How to have cells width set to the width of the layers inside ?
Aug 30th, 2000 06:59
Martin Honnen, stéphane royer,
Usually a cell is sized according to its content so I am not sure what
you aim at with your question.
But suppose you have an absolutely positioned element in a cell you
might want to adjust the cell. Here is some code to play with, it seems
to work with IE5 when the VALIGN of the cell is top:
<HTML>
<HEAD>
<TITLE>
</TITLE>
<STYLE>
</STYLE>
<SCRIPT>
function adjustTableCellWidth () {
if (document.all) {
var cell = document.all.aCell;
var layer = document.all.aLayer;
cell.width = layer.offsetWidth;
cell.height = layer.offsetHeight;
}
else if (document.getElementById) {
var cell = document.getElementById('aCell');
var layer = document.getElementById('aLayer');
cell.width = layer.offsetWidth;
cell.height = layer.offsetHeight;
}
}
</SCRIPT>
</HEAD>
<BODY>
<A HREF="javascript: adjustTableCellWidth(); void 0">
adjust cell width
</A>
<TABLE BORDER="1">
<TR>
<TD>
Kibology
</TD>
<TD ID="aCell" VALIGN="top">
<DIV ID="aLayer" STYLE="position: absolute;">
Kibology for all.
<BR>
All for Kibology.
</DIV>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>