Click to See Complete Forum and Search --> : DIV extends beyond table cell


esm
04-17-2003, 10:36 AM
I'm trying to setup some dynamic content in one of my webpages. Upon page load, all the content is hidden except for one section. The user can then click on a link (or image) to show other sections of content.

Everything seems to work fine in IE6 (i have IE 5 but not tested yet). But it doesn't work correctly in the Netscape browsers.

I have a three column table. the left and right column are for navigation and links and the middle column is for the content. Sorry, I'm pretty much stuck with the table to give the page structure without a some serious re-coding.

The content is just normal text but it will have the normal assormtment of character's - commas, apostrophes, quotemarks, tildes, carets, etc

IE6 is not pefect: If I set the width to something other than 100%, the left side is ok but the right side will eventually cover the 3rd colunm (the one on the right) as I shrink the browser window from the right. Well, this plagues NS also.

For the Netscape browsers:

The biggest problem is they don't respect the boundaries of the table cell.

NS 4.79: the DIVs for the content extend the entire width of the page and I have to use the TOP attribute to keep NS from covering the menu. (I guess I could use @import to reset the TOP to zero for IE). Overall, I prefer the way 4.79 handles this than the way the other NS version do.

NS 6/7 and Mozilla 1:
At least they respect the left side of the middle column. But the content area extends off the right edge of the screen. I can play with it and get it to stop at the right edge but I think that may cause other problems.

Also, the height setting is a problem. If I set HEIGHT: 100%; then I get a nice long (and wide) block area - a big blob. If I set the height to a specific length, then NS does not extend the DIV and just prints the extra content below the bottom edge of the DIV.

Any work arounds for Netscape?

I'm no expert with any of this.


<html>
<head>
<title>The getElementById Method</title>

<style type="text/css">

.desc{
position: absolute;
width: 100%;
height: 100%;
border: 1px solid #363636;
background-color: #BAC2F8;
padding: 10px;
display:block;
}

.contact{
position: absolute;
width: 100%;
height: 100px;
border: 1px solid #363636;
background-color: #BAC2F8;
padding: 10px;
display:block;
}
.comments{
position: absolute;
width: 100%;
height: 100%;
border: 1px solid #363636;
background-color: #BAC2F8;
padding: 10px;
display:block;
}



</style>

<script language="JavaScript1.2" type="text/javascript">
/*
Made by Martial Boissonneault © 2002 http://getElementById.com/
May be used and changed freely as long as this msg is intact
Visit http://getElementById.com/ for more free scripts and tutorials.
*/
var ns4 = (document.layers);
var ie4 = (document.all && !document.getElementById);
var ie5 = (document.all && document.getElementById);
var ns6 = (!document.all && document.getElementById);

function show(id){
// Netscape 4
if(ns4){
document.layers[id].visibility = "show";

}
// Explorer 4
else if(ie4){
document.all[id].style.visibility = "visible";
}
// W3C - Explorer 5+ and Netscape 6+
else if(ie5 || ns6){
document.getElementById(id).style.visibility = "visible";
}
}

function hide(id){
// Netscape 4
if(ns4){
document.layers[id].visibility = "hide";
}
// Explorer 4
else if(ie4){
document.all[id].style.visibility = "hidden";
}
// W3C - Explorer 5+ and Netscape 6+
else if(ie5 || ns6){
document.getElementById(id).style.visibility = "hidden";
}
}
</script>
<script>

function hideall(id,id1){
// Netscape 4
if(ns4){
document.layers[id].visibility = "hide";
document.layers[id1].visibility = "hide";
}
// Explorer 4
else if(ie4){
document.all[id].style.visibility = "hidden";
document.all[id1].style.visibility = "hidden";
}
// W3C - Explorer 5+ and Netscape 6+
else if(ie5 || ns6){
document.getElementById(id).style.visibility = "hidden";
document.getElementById(id1).style.visibility = "hidden";
}
}

</script>



</head>
<body onload="hideall('contact','comments')">

<CENTER>
<TABLE border=0 cellspacing=5 cellpadding=5>
<TR>
<TD><a href="#" onclick="show('desc');hide('contact');hide('comments')">Desc</a></TD>
<TD><a href="#" onclick="hide('desc');show('contact');hide('comments')">Contact</a></TD>
<TD><a href="#" onclick="hide('desc');hide('contact');show('comments')">Comments</a></TD>
</TR>
</TABLE>

<TABLE border=0 width=100% cellspacing=5 cellpadding=5>
<TR>
<TD width=150><!-- col 1 -->
Javascripts is a scripting language originally developed by Netscape to add interactivity and power to web documents. It is purely client side, and runs completely on the client's browser and computer.<BR><BR>
Java is completely different from JavaScript- it's more powerful, more complex, and unfortunately, a lot harder to master. It belongs in the same league as C, C++, and other more complex languages. Java programs need to be compiled before they can run, while JavaScript do not.<BR><BR>
My DHTML is the embodiment of a combination of technologies- JavaScript, CSS, and HTML. Through them a new level of interactivity is possible for the end user experience.

</TD>
<TD><!-- col 2 -->
<div id="desc" class=desc>Description<BR>
Javascripts is a scripting language originally developed by Netscape to add interactivity and power to web documents. It is purely client side, and runs completely on the client's browser and computer.
</div>
<div id="contact" class=contact>Contact<BR>
Java is completely different from JavaScript- it's more powerful, more complex, and unfortunately, a lot harder to master. It belongs in the same league as C, C++, and other more complex languages. Java programs need to be compiled before they can run, while JavaScript do not.<BR> Javascripts is a scripting language originally developed by Netscape to add interactivity and power to web documents. It is purely client side, and runs completely on the client's browser and computer.<BR><BR>
Java is completely different from JavaScript- it's more powerful, more complex, and unfortunately, a lot harder to master. It belongs in the same league as C, C++, and other more complex languages. Java programs need to be compiled before they can run, while JavaScript do not.<BR><BR>
My DHTML is the embodiment of a combination of technologies- JavaScript, CSS, and HTML. Through them a new level of interactivity is possible for the end user experience.

</div>
<div id="comments" class=comments>Comments<BR>
My DHTML is the embodiment of a combination of technologies- JavaScript, CSS, and HTML. Through them a new level of interactivity is possible for the end user experience.
</div>

</TD>
<TD width=150><!-- col 3 -->
Javascripts is a scripting language originally developed by Netscape to add interactivity and power to web documents. It is purely client side, and runs completely on the client's browser and computer.<BR><BR>
Java is completely different from JavaScript- it's more powerful, more complex, and unfortunately, a lot harder to master. It belongs in the same league as C, C++, and other more complex languages. Java programs need to be compiled before they can run, while JavaScript do not.<BR><BR>
My DHTML is the embodiment of a combination of technologies- JavaScript, CSS, and HTML. Through them a new level of interactivity is possible for the end user experience.
</TD>
</TR>
</TABLE>
</CENTER>
</body>
</html>

gil davis
04-17-2003, 11:59 AM
I can comment on the problems you are having with NS 4.

When you declare an object "position: absolute", it is taken out of the document stream and placed at top=0, left=0 of the containing document. In your case, you would think the containing document would be the table, but it's not.

I gather that you have a cell that has three different sets of text in it, and you want to control which one is visible.<script>
function show(c, it) {
if (it)
document[c].document[it].visibility = "show";
else
document[c].visibility = "show";
}

function hide(c, it) {
if (it)
document[c].document[it].visibility = "hide";
else
document[c].visibility = "hide";
}
</script>
<center>
<table border>
<tr>
<td><a href="#" onclick="show('l1');hide('l1','l2');hide('l1','l3');return false">Show Layer 1</a></td>
<td><a href="#" onclick="hide('l1');show('l1','l2');hide('l1','l3');return false">Show Layer 2</a></td>
<td><a href="#" onclick="hide('l1');hide('l1','l2');show('l1','l3');return false">Show Layer 3</a></td>
</tr>
<tr><td>&nbsp;</td>
<td id="l1" style="position: relative">
<div id="l2" style="position: absolute; visibility: hidden">some stuff 2<br>
some stuff<br>
some stuff<br>
some stuff<br>
some stuff</div>
<div id="l3" style="position: absolute; visibility: hidden">some stuff 3<br>
some stuff<br>
some stuff<br>
some stuff<br>
some stuff</div>some stuff 1<br>
some stuff<br>
some stuff<br>
some stuff<br>
some stuff
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>

esm
04-17-2003, 12:30 PM
yep, I played with most every line in the css definitions including the position attribute. without the position: absolute, the div content appears when you click the menu item but areas do not overlap. The contact area appears underneath the desc area and the comments area appears underneath the contact area.

Your example looked real interesting but I got an error msg when I tried run it.

gil davis
04-17-2003, 12:44 PM
Originally posted by esm
Your example looked real interesting but I got an error msg when I tried run it.What error?

You realize it was intended for NS 4 only, right?

JIC, I have attached the file.

esm
04-17-2003, 01:00 PM
thanks! That does work in NS4 ( just noticed your are a "die hard NS4" guy.

Now, how do I modify it for other NS versions and for IE?

gil davis
04-17-2003, 01:56 PM
See attached.

esm
04-18-2003, 08:25 AM
thanks for the help. Unfortunatley, the tbllayer2.txt suffers the same problem. Works great in IE but overflows the table cell boundary in netscape.

I have narrowed the culprit down to the position attribute. position: absolute will cause the DIV to overflow the table cell to the right and extend towards the right edge of the screen. It won't break up a word so it depend on how long the words are as it approaches the right edge of the screen as to how far it will extend to the right.

Without the position: absolute attribute, Netscape will honor the right edge of the table cell but instead of overlapping the DIVs, it places them inline. they are all hidden except for the active one and any one can be made visible by clicking on the link.

In NS 4.79 they are inline and all visible. The links don't work but they don't need to.

Conclusion: Manually setting the width sucks and will cover stuff on the right side of it as the screen shrinks. Both IE and NS suffer from this. There is a way to get NS to respect the right boundary of the table cell but then the DIVs appear inline. So I will use the @import to bring in the position: absolute ( fortunately, NS either ignores the @import or at least won't import the position attribute ) and I will just change the code to show all the DIVs if the browser is NS.

Unless there is a containing block that Netscape will honor along with the position: absolute.

khalidali63
04-18-2003, 08:29 AM
hey try this...its totally restructured,it does need tweeking but I think it could be a good start

http://68.145.35.86/temp/DivAlignmentProblem.html

esm
04-18-2003, 09:01 AM
Ouch! That will keep my brain busy all day! :) :)

Just a couple of initial things. NS6 ignores the table for the contents. Just a single blue line with the content extending below it. 4.79 doen't like the window to be re-sized but a reload fixes it.

Any way to make the middle cell vary in width? and my content comes from a database so I have to be careful that it doesn't break the javascript.

I'll work on this today!

I really appreciate your help. This is great.

Thanks