tags:

views:

333

answers:

2

Hey folks!

I can't best describe this in words, so I'll show you with pictures.

Here's how my designer intends the Gravatar images to look in the sidebar of our site:

how the designer wants it

Here's the overlay image I made (screenshotted from Photoshop):

my overlay image

Here's how it looks right now...

not quite ideal

Not quite ideal, I think you'll agree. This is the CSS code I am using:

.gravatarsidebar {
    float:left; 
    padding:0px;
    width:70px;
}

.gravataroverlay {
 width:68px;
 height:68px;
 background-image: url('http://localhost:8888/images/gravataroverlay.png');
}

And here's the XHTML (and a sprinkle of PHP to fetch the Gravatar based on the user's email address, which is fetched from our database):

<div class="gravataroverlay"></div>

        <div class="gravatarsidebar">
            <?php $gravatar_link = 'http://www.gravatar.com/avatar/' . md5($email) . '?s=68';
            echo '<img src="' . $gravatar_link . '" alt="Gravatar" />'; ?>  
        </div>

So what can I do? I can't use relative positioning as it makes the word 'Search' in the div below stay moved to the right.

Thanks for your help!

Jack

A: 

You can't use relative positioning where? On the gravatar image?

I have to wonder why you have your overlay div outside the container of the image itself. At the very least they should be siblings. Make a container that only holds the image and the overlay, then make the overlay positioned absolute at 0,0 to be on top of the image.

    <div class="gravatarsidebar">
        <?php $gravatar_link = 'http://www.gravatar.com/avatar/' . md5($email) . '?s=68';
        echo '<img src="' . $gravatar_link . '" alt="Gravatar" />'; ?>
        <div class="gravataroverlay" style="position:absolute; top:0; left:0;"></div>  
    </div>
Tesserex
I can't use relative positioning on the overlay image, since when I move it up it still leaves a 'gap' of its width thus pushing the word 'Search' over to the right. I'll give your suggestion a go though, and report back soon!
Jack Webb-Heller
I'm sorry but your code isn't working. I presume where you wrote style="position:relative you meant position:absolute, but trying it both ways and I still get the same effect. With absolute it just sits in the top left corner of the browser viewport...
Jack Webb-Heller
if you can, make the gravatarsidebar class position relative. That way it becomes the frame of reference for positioning of its children. That's why currently it goes to the top left of the browser - it's reference is the body, not the sidebar container.
Tesserex
Ah, thanks! I was wondering what was going wrong there. All works good now :)
Jack Webb-Heller
+1  A: 

Have you tried using z-index to force the two images to overlay? Maybe something like this? Here is a pseudo example.

<div class="gravatar-sidebar">
     <img class="overlay-image" src="images/gravataroverlay.png" />
     <?php $gravatar_link = 'http://www.gravatar.com/avatar/' . md5($email) . '?s=68';
     echo '<img src="' . $gravatar_link . '" alt="Gravatar" class="gravatar-image"/>'; ?>
</div>

/*CSS*/
.gravatar-sidebar {float:left;padding:0px;width:70px;position:relative;}
img.overlay-image{position:absolute;left:0px;top:0px;z-index:10;}
img.gravatar-image{position:absolute;left:0px;top:0px;z-index:1;}
Jon
That achieves exactly the effect I want! Thank you very much for your help! :)
Jack Webb-Heller