How can i overlay an 10x10px image on top of another image? [duplicate]
I have a user avatar on my website. Simple image tag:
<img src="foo.jpg" class="userphoto" width="48" height="48" alt="">
Now, i want to float an image (Facebook Icon - 10x10px) over this image on the top left corner of the image.
This is to signify that the user is authenticated to Facebook.
How can i do this? CSS styling on the image tag, or will i have to have a seperate div with absolute positioning?
Doesn't need to be transparent or anything, just needs to be positioned exactly in the top-left corner.
Of course i cant just physically modify the image, as i need to determine whether to overlay the image dynamically based on the Facebook status. But i was hoping to dynamically add a css class.
Any ideas?
ANSWER:
Got it working with a combination of both answers. Used a div instead of another image.
HTML:
<div class="foo">
<div class="fboverlay"&g开发者_如何学运维t;</div>
<a>
<img src="foo.jpg" class="userphoto" width="48" height="48" alt="">
</a>
</div>
CSS:
.foo
{
position: absolute;
top: 0;
right: 0;
}
.fboverlay
{
background-image: url('/image/facebook/logo.gif');
position: absolute;
z-index: 1;
top: 10px;
left: 10px;
width: 10px;
height: 10px;
}
Thanks for the help.
I know I'm not using the exact dimensions you wanted, but here's a working example for you. (You would need the parent ".main_photo" div to be the dimensions of the main photo.)
.main_photo{
position:relative;
width:80px;
height:80px
}
.inlay{
position:absolute;
top:5px;
right:5px
}
<div class="main_photo">
<img src="https://secure.gravatar.com/avatar/?s=200&d=mm&r=pg" />
<img class="inlay" src="https://www.rit.edu/news/lib/views/public/images/dateline_images/facebook_icon.gif" />
</div>
First you have to position
it - either relative or absolute usually.
Secondly, you have to set a z-index
if there are other positioned elements, though you may not necessarily need one.
Using top/left
or bottom/right
combinations layer the image over the other one.
This is advice without seeing any html/css. It will obviously differ depending on the situation.
#el-on-top { position:absolute; top:0; left:0; z-index:1; }
You may need to set position:relative
so the AP'd element's top is relative to something, instead of say, the wrapper or the entire page.
精彩评论