Click to See Complete Forum and Search --> : Positioning Div
I have two tables,each wrapped in a div, next to eaxh other(one table on left and the other on right).If I hide the first div on the left, Is it possible that the second div on the right side of the page moves to left(In other words, it should take the place of first div).When I show the first div, the second div should appear in its original positon (on RHS).
I'm not sure if this can be done.Any ideas/suggestions?
Many Thanks,
SniperX
05-05-2003, 12:17 AM
You can check if the first one is hidden and if it is then you just change the alignment of the second one..
That might work - i am but a lowly c programmer, i know little of js...
Regards
MW
You mean div alignment?I tried that and it didnt work
AdamGundry
05-05-2003, 10:51 AM
You might be able to use the float (http://www.w3.org/TR/CSS2/visuren.html#propdef-float) CSS property - set both divs to the same float direction, then if one is display: none the other should take its place.
Adam
That didnt work either.Here's my code:
Thanks,
<html>
<head>
<script type="text/javascript">
var isNS = navigator.appName.indexOf("Netscape") != -1
var isIE = navigator.appName.indexOf("Microsoft") != -1
function show() {
if (isNS) document.layers["d1"].visibility = "show";
if (isIE) document.all.d1.style.visibility = "visible";
}
function hide() {
if (isNS) document.layers["d1"].visibility = "hide";
if (isIE) document.all.d1.style.visibility = "hidden";
}
</script>
<title></title>
</head>
<body>
<a href="javascript:hide()">Hide Table 1</a>
<p>_ _<a href="javascript:show()">Show Table 1</a><br>
<br>
</p>
<table>
<tr>
<td>
<div id="d1" style="position:relative;">
<table bgcolor="#EFEFEF" border="1">
<tr>
<td>table 1</td>
<td>table 1</td>
<td>table 1</td>
</tr>
<tr>
<td>table 1</td>
<td>table 1</td>
<td>table 1</td>
</tr>
<tr>
<td>table 1</td>
<td>table 1</td>
<td>table 1</td>
</tr>
<tr>
<td>table 1</td>
<td>table 1</td>
<td>table 1</td>
</tr>
</table>
</div>
</td>
<td>
<div id="d2" style="position:relative;float:left;">
<table bgcolor="LIGHTBLUE" border="1">
<tr>
<td>table 2</td>
<td>table 2</td>
<td>table 2</td>
</tr>
<tr>
<td>table 2</td>
<td>table 2</td>
<td>table 1</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</body>
</html>
You could try to use innerHTML and re-code the whole thing... Or, a better way (?), would be to use position:absolute;left:[number depending on resolution of screen];
Thanks Jona, that worked :)
I used the left property in show & hide functions:
function show() {
if (isNS) document.layers["d1"].visibility = "show";
if (isIE) document.all.d1.style.visibility = "visible";
if (isIE) document.all.d2.style.left = "215px";
}
function hide() {
if (isNS) document.layers["d1"].visibility = "hide";
if (isIE) document.all.d1.style.visibility = "hidden";
if (isIE) document.all.d2.style.left = "8px";