Link to home
Start Free TrialLog in
Avatar of Brad Bansner
Brad Bansner

asked on

CSS: setting width of DIV with overflow:auto set

I have a DIV which contains a large table of data, too wide for most users' monitors. I had it styled like this:

#membertable{width:877px;overflow:auto;}

That way, it fit within the screen design, and if its too wide, the data just scrolls inside the DIV. But now, the client wants the screen to stretch to use as much of the user's monitor width as possible. So I recoded the screen design so that the page template uses all of the width.

I tried changing my CSS on the DIV to this:

#membertable{width:100%;overflow:auto;}

However, now it forces the DIV to as wide as it needs to go to include all of the table data. The entire screen scrolls left-to-right now, the DIV itself is wider than the monitor. I also tried this, but the same thing happens

#membertable{overflow:auto;}

What I want, is for the DIV to stretch as far left-to-right as it can go without making the entire screen scroll (DIV same width as the user's monitor), and then the contents within that DIV should scroll (overflow:auto;) if the table is too wide to fit within the DIV. Is this possible? I don't see how I can set a specific width because I don't know the size of the user's monitor, how their document window is positioned, etc. And 100% seems to just make it stretch as far as it needs to go.

Thank you!
ASKER CERTIFIED SOLUTION
Avatar of zappafan2k2
zappafan2k2

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Brad Bansner
Brad Bansner

ASKER

That is getting me closer, I think. Here is a test version of my page:

https://www.interactivehealthpartner.com/mfc_manage-enrolled-members-test.asp

Relevant code attached.

For some reason, the absolute-positioned DIV is breaking out of the main content area. I have membertablewrapper with a red border, it appears that membertable (green border) is not staying inside it for some reason, even though I have a "clear:both;" afterwards.

The page template is built with a table, but its width is not set. For some reason, the DIV still isn't forcing that wider.

Note that if I remove membertablewrapper altogether, the absolute DIV goes all the way to the top of the screen and it breaks out of the page template table (no white background), on top of everything else... BUT... the width is exactly the way I wanted, to the available left-to-right space on the screen.

So if I can get that to work, but keep it within the page template table, this will be solved.

I don't know if you have any other suggestions, otherwise I'll just need to keep muddling through it.

Thanks!
#membertablewrapper{position:relative;width:100%;border:1px solid #ff0000;}
#membertable{position:absolute;top:0px;left:0px;right:0px;overflow:auto;border:1px solid #00ff00;}
div.clear{clear:both;}

<div id="membertablewrapper">
<div id="membertable">

<table>data here</table>

</div>
<div class="clear"></div>
</div>

Open in new window

Thanks for your advice, I was able to cheat a little and get this to work.
And, I love Frank Zappa!