views:

624

answers:

5

We have a web page with this general structure:

<div id="container">
  <div id="basicSearch">...</div>
  <div id="advancedSearch" style="display: none">...</div>
<div>

With this CSS:

#container { MARGIN: 0px auto; WIDTH: 970px }
#basicSearch { width:100% }
#advancedSearch{ width:100%;}

We have a link on the page that lets the user toggle between using the "basic" search and the "advanced" search. The toggle link calls this Javascript:

var basic = document.getElementById('basicSearch');
var advanced = document.getElementById('advancedSearch');
if (showAdvanced) {
 advanced.style.display = '';
 basic.style.display = 'none';
} else {
 basic.style.display = '';
 advanced.style.display = 'none';
}

This all works great in IE.

It works in Firefox too - except - when we toggle (ie: show/hide) from one div to the other, the page "moves" in Firefox. All the text in the "container" moves about 5px to the left/right when you toggle back and forth. Anyone know why?

+1  A: 

I don't know why, but if you install Firebug a Firefox plug in you can use it to debug your problem.

Firebug has saved my hours of debugging time when it comes to CSS and showing and hiding divs.

With firebug you can view what may be different between the two divs.

From firefox, just choose the Tools Menu, then click Ad-Ons, then click Get Ad-Ons and search for firebug.

One thing that you could try is to hide before you show, this may have less flicker. If you are causing the page to get taller, this could be the source of your trouble.

I hope this helps.

Steve Stedman
+5  A: 

Is it causing a scrollbar to appear / disappear?

Greg
Ah, yes it is. I see that if I filter my data so the scrollbar doesn't appear/disappear, than this issue goes away. Is there some setting to tell Firefox "not to worry about the scrollbar status"?
Marcus
You can set html { overflow:scroll; } (or is that body {}, I forget)...
Greg
I put it in the body and it kind of worked. It got rid of the issue although - in IE the screen is displayed kind of like there are two vertical scrollbars and in FF, when I show the div, a horizontal scrollbar now appears.
Marcus
+3  A: 

Toggling content can make the page content taller. Check whether this makes a scrollbar appear, as this will affect the page width slightly.

Ron DeVera
Yes, it is making the scrollbar appear/disappear. How can one deal with the scrollbar appearing/disappearing so the page content doesn't "move"?
Marcus
One dirty trick is `html{ height:100%; padding-bottom:1px }`, which forces the page to be 1px taller than it needs to be.
Ron DeVera
That didn't appear to work.
Marcus
What does appear to work is: HTML { height: 101% }
Marcus
+1  A: 

Check your XHTML is well formed, sounds like a dangling DIV (firebug will help with this).

On a side note jquery has some really nice animations that make this switch much nicer on the eyes.

Jeff
A: 

What I ended up doing was this: HTML { OVERFLOW-Y:SCROLL; OVERFLOW-X:HIDDEN; }

Here's a good related SO post.

Marcus