tags:

views:

35

answers:

2

I have following html

<table>
    <tr>
        <td class='tclone' id='clone'></td>
         <td class='loader' id='loader'>
              <div id='tdiv' style="height:630px; width:835px; overflow:auto;"></div>
         </td>
    </tr>
</table>

I open this HTML in a new window and JavaScript append contents to tclone and tdiv. tdiv specifically loads a image. I needed to give the width and height parameters to div as it was overflowing past the window, also overflow parameter allows scroll-bar inside td. This solution works with fixed size window - but I want a mechanism, such that when user resizes the window the div also gets expanded and the div scroll-bars are also adjusted to match the new window size.

any suggestions?

A: 

You need to specify the width and height in percentage then:

<div id='tdiv' style="height:30%; width:30%; overflow:auto;"></div>

You should adjust the percent values though.

Sarfraz
but this doesn't change the scrollbar size when window is resized.
Sujit
@Sujit: Try adjusting the percent values.
Sarfraz
since the div is inside td element, the resizing the window doesn't change the width and height of div element. I tried playing around with multiple values. Do I need to adjust width and height of the parent td or table element?
Sujit
@Sujit: Yes div is inheriting values from their parent, try with them too.
Sarfraz
A: 

On the table set "table-layout: fixed". Make sure the table and td widths are % based. You shouldn't need a width on the div.

If the content that overflows the div is not contained in another tag, you'll need a wrapper around tdiv.

An alternative to % widths would be setting the min-width and/or max-width attributes.

mikemerce
I changed all the values to % the code.but the tdiv % values don't change the tdiv size on window resizing.when I mention <div style='width:30% overflow:auto;'> the div size is fixed to 30% of the image that it has not 30% of window width.
Sujit