tags:

views:

424

answers:

4

I am doing stuff with ajax progress bars and stuff...

Basically I have a hidden div that says "Loading" in it, and beneath it I have a visible div with my content in.

When it is loading, it fades the content div out, makes the hidden div visible, and moves it via javascript/relative positioning to be in the middle of the content.

It looks quite badass but unfortunately when the div is made visible, even though its relatively positioned, it takes up a line so my content moves down.

Do you know how I can stop it from taking up space when it is made visible?

Edit: Someone removed the tag it seems

The loading div starts off display none, so it takes up no space, and then when it is made visible, it starts taking up space, even though it is positioned relatively.

I could use visible and non-visible, but then it would force my content window down all of the time.

It looks like absolute positioning is the way to go.

What I want to do is combine absolute and relative positioning. I am trying to get the absolute coordinates of the content div and setting its location that way, but without success yet.

Edit: I just re-read your answer and you have done exactly that. Thank you!

+10  A: 

"Do you know how I can stop it from taking up space when it is made visible?"

Position it absolutely.

div#theParent { position:relative; height:200px; width:640px;
                top:50px; left:50px; }
div#theChild  { position:absolute; height:100px; width:400px; 
                top:50px; left:120px; }

<div id="theParent">
  <div id="theChild">
    <p>This div is absolutely positioned to a relatively-positioned parent.
  </div>
</div>
Jonathan Sampson
Why the downvote. He asked how to keep a relatively-positioned item from shifting siblings when it is visible.
Jonathan Sampson
+1 from me - unless I'm misreading the question, yours is the only answer that answers his question (which is about how to stop it moving things when made visible, not how to stop it taking up space when invisible).
Dominic Rodger
if you play with absolute position, of course the div will not move... But even if the question was asked in that way, the good practice is to use the 'display:none' instead of the 'visible:hidden'... That is why I vote down.
enguerran
let's him try both solutions and he will choose the correct 'as-he-wants' answer.
enguerran
I think this is right but I am not sure how to implement it to get an absolutely positioned item, positioned relative to the parent...
SLC
Ok, the question clearer make my answer wronger.
enguerran
SLC, you must set the parent to position:relative, so that the absolute coordinates are based on the parents position in the document. Look at my example again.
Jonathan Sampson
Figured it out, thank you very very much. Some people are so wise, but this site is teaching me such a huge amount.
SLC
SLC: Good work! Wisdom comes with time. You'll soon be the guy with all the answers ;) Just remember to come back and share your wisdom when you can :)
Jonathan Sampson
@enguerran: actually display:none / visibility:hidden pose an accessibility problem with screen readers (as they don't offer javascript more often than not), the recommandation is therefore to move elements out of the screen with ridiculous absolute positions (-999em for example)
Matthieu M.
+1  A: 

When you want to make it invisible, make it really invisible with style="display:none". There are many ways to do this...not sure how you have this set up or how you're altering your dom elements. Provide some more context (doing this with Ajax controls, custom JavaScript, a library like jQuery, etc), and we can give you a more specific solution.

Rich
A: 

You can try various things, like. Depends on how your code is constructed. Since you didn't provide an example :)

display: none;
height:0px 
line-height: 0px;
font-size: 0px;
Ólafur Waage
+1  A: 

You have to play with the display option, not the visible option :

Tip: Even invisible elements takes up space on the page. Use the "display" property to create invisible elements that do not take up space!

see w3schools

enguerran