views:

293

answers:

3

Hi,

I have a login form on my website that displays when a user clicks a button. It is a div that floats over other content. It only takes up a small portion of the page (directly below the sign in link).

It all works fine apart from one small thing. It displays aligned to the left of the sign in link (i attempted a diagram below).

|sign in|

|sign in stuff here|

I actually want it to look like this (align to the right of the sign in link):

                |sign in|

|sign in stuff here|

This is my HTML:

        <div class="clear">
            <a class="button" id="SignInBtn" href="#" onclick="toggleSignInBox(); return false;"><span id="spanSignIn">Sign In / Register <img src="../../Content/shared/arrow_down.png" border="0" /></span></a>
        </div>
        <div id="signinbox" style="display:none;">
            <p>Who would you like to sign in with?</p>
            <p>Google</p>
            <p>Yahoo</p>
            <p>Other</p>
        </div>

And the CSS for the sign in box:

signinbox {background-color:#C1DEEE; padding:10px; z-index:1; position: absolute; top:66px; }

Is it possible to do this in just CSS?

Thanks

+1  A: 

I think you may want to try

float: right

or

text-align: right

Unknown
Thanks, but the float or the text-align did not work.
+2  A: 

Wrap the signin info inside another div and call it inner-signin then position that relative to the absolute positioned outter div. You may also have to set the width on the absolute positioned outter div.

div.inner-signinbox {
    position: relative;
    right: 20px;
}

signinbox {
    width: 250px; //ADD A WIDTH
    background-color:#C1DEEE; 
    padding:10px; 
    z-index:1; 
    position: absolute;
    top:66px; 
}

If that does not work, why not just add a "left" property to the signingbox to set the horizontal position as well as the vertical. Is there a reason you don't can't absolute position the element with x and y?

jW
I'll give this a try.
Just realised, i need to use absolute so it floats above other elements.
also try changing your position: absolute in the CSS to relative. Playing with this a little can be tricky, but you will get it with just a little patience.
jW
When i set it to relative it doesn't 'float' over the other elements, it just shoves them out the way. I want it to appear on top of all other elements without moving anything.
i updated my response. Give that a try.
jW
Thanks, it positions the text, but not the background. the background part stays where it is and the text moves over. I tried positioning by x and y but it goes awry when the browser is resized.
move the background into the inner div, or add margin/padding to the outer div to accomodate
jW
A: 

Put the sign-in stuff inside the div containing the sign-in button.

Make the container position: relative.

Then give the sign-in stuff position: absolute; and right: 0;.

Incidentally, take care here; requiring Javascript merely to log in is pretty rude. A lot of people run NoScript for a variety of reasons.

Eevee
Thanks, i was planning on having a noscript tag with an alternative. Might as well make the site look pretty for people with javascript :)