Solved

Scrollable div with height=100%

Posted on 2002-03-12
12
478 Views
Last Modified: 2008-03-04
I try to make a page that will have a long table, and a title above the table, and I want the table to be scrollable WITHOUT scrolling the title. In other ways, I want a fix title and a scrollable table. the way I see it I can use either frames or scrollable DIVs. I preffer scrollable because this entire page is already in two sets of frameset. SO, the problem is, that if I set a fixed height to the DIV, everything is fine, BUT if a set the DIV height to 100% and the top to be 22px, the DIV spreads itself to the entire size of the frame but because it starts 22px form the top, it overflows 22px from the bottom, so the end of the scrollbar is unreachable.
here is the code: (open it in browser, and make the window smaller then the table - which I made shorter for the question - then you'll see the problem)

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Asset List</title>
<link rel="stylesheet" href="/XmpieSite/Utils/mainstyle.css" type="text/css">
<SCRIPT language="JavaScript" SRC="/Utils/XMPiEScripts.js">
</script>
</head>

      <body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" >
    <div id="Buttons" style="position:absolute;top:0;overflow-X:hidden;overflow-y:hidden;width:100%;height:22;z-index:1">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr bgcolor=#003399>
                  <td nowrap class="sectionHead" valign="middle">&nbsp;Campaign Assets</td>
                  <td nowrap align="right" valign="middle">
                        <table border="0" cellspacing="0" cellpadding="0">
                              <tr>
                                    <td><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('openbtn','','../../images/open-over.gif',1)"><img alt="Open Asset" name="openbtn" border="0" src="../../images/open.gif" width="75" height="21" onClick="AssetOpen.submit();"></a></td>              
                                    <td><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('deletebtn','','../../images/delete-over.gif',1)"><img alt="Delete Asset" name="deletebtn" border="0" src="../../images/delete.gif" width="75" height="21" onClick="confirmFormSubmition(AssetDelete,'Asset')"></a></td>
                                    <td><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('newbtn','','../../images/new-over.gif',1)"><img alt="New Asset" name="newbtn" border="0" src="../../images/new.gif" width="75" height="21" onClick="AssetNew.submit();"></a></td>
                              </tr>
                        </table>
                  </td>
            </tr>
      </table>
      </div>
      <div id="tableDiv" style="position:absolute;top:22;overflow-X:visible;overflow-y:auto;width:100%;height:100%;">
            <table width="100%" border="0" cellspacing="2" cellpadding="0">
                  <tr>
                        <td nowrap width="24" align="center">&nbsp;</td>
                        <td nowrap class="listHeader"><img src="../../images/sort.gif" width="16" height="16" align="absmiddle"><a href="#">Asset</a></td>
                        <!--<td nowrap class="listHeader"><img src="../../images/sort-no.gif" width="16" height="16" align="absmiddle"><a href="#">Type</a></td>
                        <td nowrap class="listHeader"><img src="../../images/sort-no.gif" width="16" height="16" align="absmiddle"><a href="#">Size</a></td>
                        <td nowrap class="listHeader"><img src="../../images/sort-no.gif" width="16" height="16" align="absmiddle"><a href="#">Upload Date</a></td> -->
                  </tr>

                  <tr>
                        <td nowrap width="24" align="center" class="listtext"><img src="../../images/nodes/listicons/unknown.gif" width="16" height="16"></td>
                        <td nowrap class="listtext"><a href="javascript:setAssetDetails(1,'bouquet1.jpg','//ZVIKA/XMPiEData/1/3/assets//bouquet1.jpg', AssetOpen, AssetSelect)" ondblclick="setAssetDetails(1,'bouquet1.jpg','//ZVIKA/XMPiEData/1/3/assets//bouquet1.jpg', AssetOpen, AssetSelect)">bouquet1.jpg</a></td>
                        <!--<td nowrap class="listtext"><a href="#" target="ComponentDetails" onClick="setAssetDetails(1,'bouquet1.jpg','//ZVIKA/XMPiEData/1/3/assets//bouquet1.jpg')">bouquet1.jpg</a></td>
                        <td nowrap class="listtext">JPEG Image</td>
                        <td nowrap class="listtext">145kb</td>
                        <td nowrap class="listtext">07-Jul-2001 10:32</td> -->
                  </tr>

                  <tr>
                        <td nowrap width="24" align="center" class="listtext"><img src="../../images/nodes/listicons/unknown.gif" width="16" height="16"></td>
                        <td nowrap class="listtext"><a href="javascript:setAssetDetails(2,'bouquet2.jpg','//ZVIKA/XMPiEData/1/3/assets//bouquet2.jpg', AssetOpen, AssetSelect)" ondblclick="setAssetDetails(2,'bouquet2.jpg','//ZVIKA/XMPiEData/1/3/assets//bouquet2.jpg', AssetOpen, AssetSelect)">bouquet2.jpg</a></td>
                        <!--<td nowrap class="listtext"><a href="#" target="ComponentDetails" onClick="setAssetDetails(2,'bouquet2.jpg','//ZVIKA/XMPiEData/1/3/assets//bouquet2.jpg')">bouquet2.jpg</a></td>
                        <td nowrap class="listtext">JPEG Image</td>
                        <td nowrap class="listtext">145kb</td>
                        <td nowrap class="listtext">07-Jul-2001 10:32</td> -->
                  </tr>

                  <tr>
                        <td nowrap width="24" align="center" class="listtext"><img src="../../images/nodes/listicons/unknown.gif" width="16" height="16"></td>
                        <td nowrap class="listtext"><a href="javascript:setAssetDetails(3,'bouquet3.jpg','//ZVIKA/XMPiEData/1/3/assets//bouquet3.jpg', AssetOpen, AssetSelect)" ondblclick="setAssetDetails(3,'bouquet3.jpg','//ZVIKA/XMPiEData/1/3/assets//bouquet3.jpg', AssetOpen, AssetSelect)">bouquet3.jpg</a></td>
                        <!--<td nowrap class="listtext"><a href="#" target="ComponentDetails" onClick="setAssetDetails(3,'bouquet3.jpg','//ZVIKA/XMPiEData/1/3/assets//bouquet3.jpg')">bouquet3.jpg</a></td>
                        <td nowrap class="listtext">JPEG Image</td>
                        <td nowrap class="listtext">145kb</td>
                        <td nowrap class="listtext">07-Jul-2001 10:32</td> -->
                  </tr>

                  <tr>
                        <td nowrap width="24" align="center" class="listtext"><img src="../../images/nodes/listicons/unknown.gif" width="16" height="16"></td>
                        <td nowrap class="listtext"><a href="javascript:setAssetDetails(4,'bouquet4.jpg','//ZVIKA/XMPiEData/1/3/assets//bouquet4.jpg', AssetOpen, AssetSelect)" ondblclick="setAssetDetails(4,'bouquet4.jpg','//ZVIKA/XMPiEData/1/3/assets//bouquet4.jpg', AssetOpen, AssetSelect)">bouquet4.jpg</a></td>
                        <!--<td nowrap class="listtext"><a href="#" target="ComponentDetails" onClick="setAssetDetails(4,'bouquet4.jpg','//ZVIKA/XMPiEData/1/3/assets//bouquet4.jpg')">bouquet4.jpg</a></td>
                        <td nowrap class="listtext">JPEG Image</td>
                        <td nowrap class="listtext">145kb</td>
                        <td nowrap class="listtext">07-Jul-2001 10:32</td> -->
                  </tr>

                  <tr>
                        <td nowrap width="24" align="center" class="listtext"><img src="../../images/nodes/listicons/unknown.gif" width="16" height="16"></td>
                        <td nowrap class="listtext"><a href="javascript:setAssetDetails(5,'bouquet5.jpg','//ZVIKA/XMPiEData/1/3/assets//bouquet5.jpg', AssetOpen, AssetSelect)" ondblclick="setAssetDetails(5,'bouquet5.jpg','//ZVIKA/XMPiEData/1/3/assets//bouquet5.jpg', AssetOpen, AssetSelect)">bouquet5.jpg</a></td>
                        <!--<td nowrap class="listtext"><a href="#" target="ComponentDetails" onClick="setAssetDetails(5,'bouquet5.jpg','//ZVIKA/XMPiEData/1/3/assets//bouquet5.jpg')">bouquet5.jpg</a></td>
                        <td nowrap class="listtext">JPEG Image</td>
                        <td nowrap class="listtext">145kb</td>
                        <td nowrap class="listtext">07-Jul-2001 10:32</td> -->
                  </tr>

                  <tr>
                        <td nowrap width="24" align="center" class="listtext"><img src="../../images/nodes/listicons/unknown.gif" width="16" height="16"></td>
                        <td nowrap class="listtext"><a href="javascript:setAssetDetails(6,'bouquet6.jpg','//ZVIKA/XMPiEData/1/3/assets//bouquet6.jpg', AssetOpen, AssetSelect)" ondblclick="setAssetDetails(6,'bouquet6.jpg','//ZVIKA/XMPiEData/1/3/assets//bouquet6.jpg', AssetOpen, AssetSelect)">bouquet6.jpg</a></td>
                        <!--<td nowrap class="listtext"><a href="#" target="ComponentDetails" onClick="setAssetDetails(6,'bouquet6.jpg','//ZVIKA/XMPiEData/1/3/assets//bouquet6.jpg')">bouquet6.jpg</a></td>
                        <td nowrap class="listtext">JPEG Image</td>
                        <td nowrap class="listtext">145kb</td>
                        <td nowrap class="listtext">07-Jul-2001 10:32</td> -->
                  </tr>

                  <tr>
                        <td nowrap width="24" align="center" class="listtext"><img src="../../images/nodes/listicons/unknown.gif" width="16" height="16"></td>
                        <td nowrap class="listtext"><a href="javascript:setAssetDetails(7,'bouquet7.jpg','//ZVIKA/XMPiEData/1/3/assets//bouquet7.jpg', AssetOpen, AssetSelect)" ondblclick="setAssetDetails(7,'bouquet7.jpg','//ZVIKA/XMPiEData/1/3/assets//bouquet7.jpg', AssetOpen, AssetSelect)">bouquet7.jpg</a></td>
                        <!--<td nowrap class="listtext"><a href="#" target="ComponentDetails" onClick="setAssetDetails(7,'bouquet7.jpg','//ZVIKA/XMPiEData/1/3/assets//bouquet7.jpg')">bouquet7.jpg</a></td>
                        <td nowrap class="listtext">JPEG Image</td>
                        <td nowrap class="listtext">145kb</td>
                        <td nowrap class="listtext">07-Jul-2001 10:32</td> -->
                  </tr>

            </table>      
      </div>
</body>
</html>
0
Comment
Question by:Zvika
12 Comments
 
LVL 19

Expert Comment

by:DreamMaster
ID: 6856092
Hmmm...first of all...

The way you are doing this now you will never get the button div to stay where it is...it will move along with the scrollbar...as far as I know overflow is only really supported on the body tag, could be wrong there though

There are other types of solutions to do what you want to do...scrollable layers are very well doable...

Just have a look at:

http://www.thekitchen.nl/default.asp?Page=/welkom/main.asp

See in the middle of the screen...there is text there and it is scrolled by going over 2 small arrows at the right side of it, if this is more like what you want I can make an easier version of it for you so you could use that...

Max.
0
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 6856101
You could simply set the height of the div to 90%. That works as long as the page is more than 220 pixels high. There will be a small unused area at the bottom of the page, but at least that's better than having an overflow...

You could also write a javascript function that sets the height of the div to the available height minus the height of the title and borders. Put a call to the function in the body onload event and the window resizeend event. This will be quite browser-specific, though...
0
 
LVL 4

Author Comment

by:Zvika
ID: 6856186
GreenGhost
I thoght about both of your ideas and tried them before posting this question. The thing is, that that page is one frame in a frame set that is resizeable, so 90% (or any other compremised %) is not good enough, because the user may resize it to anything between 0 to 800 px.
This is also true for your second idea - I made a script that fix it in OnLoad, but afterwards, if the user changes the frameset sizes, or the entire explorer window size - the problem will occur.

Any other ideas?
(and - is that the right behaviour for 100% height?)
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 6856468
You will not get it to work correct with height expressed as a percentage.  if you want the div to be scrollabe and work correctly you have three requirements and a limitation.

The limitation is IE only.  The requirements: It must be absolutely positioned;  It must specify overflow-y:scroll or overflow-y:auto; and it must have a fixed height in pixels.

You can change the height dynamically with scriping, but if you use a percentage you can play around with it all you want; you will not get it to work reliably.  I have don hundreds of scrolling divs what you want is simple within the limits of the technology, but it is very easy to break. The percentage is a percentage of the total window, , not what is left so no matter what you do and no matter what percentage you use, it is not going to show the way you want it too for all sizes and resolutions.

Cd&



Cd&
0
 
LVL 4

Author Comment

by:Zvika
ID: 6856511
Cd&
How can I change the height dynamicly? I should do it if the user changes the window size, or the framesset division... Do you have some hints for me?
0
 
LVL 4

Author Comment

by:Zvika
ID: 6856540
Cd&
How can I change the height dynamicly? I should do it if the user changes the window size, or the framesset division... Do you have some hints for me?
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 6856696
In the head of the page:

<script language="JavaScript">
<!--
   function resetHgt()
   {
      document.getElementById('tableDiv').style.height=document.body.clientHeight-22;
   }
//-->
</script>

Then in the body tag:

<body onLoad="resetHgt()" onResize="resetHgt()">

That should keep it 22px from the top with a height equal t the res of the page.  It might need an adjustment of a few pixels depending on the margin settings.

Cd&
0
 
LVL 4

Author Comment

by:Zvika
ID: 6856712
This will only work in IE on Windows I guess...
Right?
(I need at least IE 5+, NN 6+ for both MAC & WIN)

0
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 100 total points
ID: 6856832
IE 5+ no problem.
Netscrap 6+  I'm not sure if it even supports overflow. If it does then you will probably need to use window.innerHeight to get the page height, and no guarantees on whether you have to make different adjustments for IE and Netscrap.

As for MAC... anything on a MAC is a crap shoot you don't know what will work until you try it.  I don't support MAC, I don't what it will let you do with this.

Cd&
0
 
LVL 4

Author Comment

by:Zvika
ID: 6859815
Thanks Cd&.
I couldn't graded you with an A, as it is actually a workaround, not a solution, plus the fact that I should still make some research for Mac, & Netscape.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 6860372
If there was a perfect solution.  I would have given it to you.  If a workaround is the best solution then you sitll got the best possible answer, whether you like the limits of the technology or not.  

I see no point in trying to help you in the future, because you did not grade my solution, but the limits of the technology.  Send you complaints to Microsoft and Netscrap.  I didn't invent the technology.

Cd&
0
 
LVL 4

Author Comment

by:Zvika
ID: 6860458
Cd&
You read only the first part of my comment.

>> plus the fact that I should still make
>> some research for Mac, & Netscape.

as your solution was only for IE 5+ in Win, though I needed NN 6+ for Win and IE 5+ & NN 6+ for Mac. So I graded your solution, which is probably the best there is in the technology, but gavr you B as this is only partial answer (1/4 of what I need - one browwser out of four).

Please don't be so rude... (not to me, and even not to Apple & Netscape - or actually Mozilla)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now