views:

34

answers:

3

I need some advanced CSS help here. I have a login button and a register button, I only want one to show up at a time. If the user is not logged in, the register button should appear on top of the login button. We have a complex & crazy backend which will generate the code for the register button if the server thinks the user is not logged in. But both will be output by the server, the register button only if the user is logged in. Is there anything that can be done with absolute positioning to move one on top of the other?

+5  A: 

Why put one on top of the other? There's a "proper" way of hiding things in CSS, using the display property:

.register_button { display: none; }

Then, in your HTML:

<button type="button" class="register_button">Will not show up!</button>
Dominic Rodger
+1 This is obviously the best solution. I only included mine to show him literally how to do what he wanted to do.
Robusto
upvoted for a good solution
Pasta
+2  A: 

Yes, there is.

.button1 {
  position: absolute;
  left: 100;
  top: 100;
  z-index: 1000;
}

.button2 {
  position: absolute;
  left: 100;
  top:100;
 z-index: 1001;
}

But I don't like doing this. For one thing, it removes you from the natural flow of the markup and forces you to position the button no matter what content comes above it. For another, what if the lower button is larger than the top? Then you have a problem with edges of the lower one visible.

Use Dominic's solution above. It's much better.

Robusto
+1 for answering the question as asked - that's helpful too!
Dominic Rodger
+1 for the solution I need!
Pasta
Any reason why this does not work on Google Chrome but works on Firefox?
Pasta
@Pasta - show us your markup and your CSS.
Dominic Rodger
A: 

First you need to inspect id of the element using tool like firebug (addon of firefox) then you need to use that id in css to position it, let's suppose the button has id myid, you should do this in CSS:

#myid
{
  position:absolute;
  top:100px; /* adjust this */
  left:100px; /* adjust this */
}
Sarfraz