|
Posted by Ben C on September 24, 2006, 5:46 pm
Please log in for more thread options
> [...]
> The solution you suggest will work but it will also have to monitor
> the onresize event of the top level table or window to constantly
> recompute the proper size of the div. I was trying to avoid this....
Good point.
> Ben C wrote:
>>
>> That's just what auto width and height mean, but the problem is they're
>> treated as minimums.
>>
>> If the <div id="scrollingPane"> has nothing much in it, the table
>> formatter sizes the <td> it's in so that the other rows and columns and
>> the table itself mostly get the sizes you asked for.
>>
>> Ideally you'd like to take the computed width and height of that <td>
>> and set them on the <div>, so that its content overflows and can be
>> scrolled by setting overflow: scroll.
>>
>> The problem is that as soon as you put the content in the <div>, the
>> table formatter no longer computes the dimensions of the <td> the same--
>> it now (in accordance with CSS 2.1 17.5.3) makes the <td> big enough for
>> its content.
>>
>> The only fix I can come up with involves scripting:
>>
>> I added this to the <head> element:
>>
>> <script language="javascript">
>> function resize()
>> {
>> var td = document.getElementById("scrollingCell");
>> var style = getComputedStyle(td, null);
>>
>> // Get the height computed by the table formatter for this cell in the
>> // absence of any content.
>> var div = document.getElementById("scrollingPane");
>>
>> // Fix on those dimensions
>> div.style.width = style.width;
>> div.style.height = style.height;
>>
>> // And put the content back
>> document.getElementById("content").style.display = "block";
>> }
>> window.onload = resize;
>> </script>
>>
>> I gave the <td> above <div id='scrollingPane'> an id of 'scrollingCell',
>> and enclosed <div id='scrollingPane'> in another div like this:
>>
>> <div id="content" style="display: none">
>> Line 01<br>
>> ...
>>
>> The browser first formats the <td> as if it had no content. This works
>> fine-- the table is 100% x 100% so fills the viewport, the nav bar has a
>> width, the caption has a height, and the td gets the space that's left.
>>
>> Then we grab those values with getComputedStyle, set them in stone, and
>> put the content back, which now overflows and produces scrollbars.
>>
>> I'd also be interested to see if there's a better solution that doesn't
>> involve scripting.
|