I have a picture on a page, and I simply want to draw a link with a small graphic in the upper left corner of the picture. Is there any way to do this? to overlap it on the picture appropriately?
Asked
Active
Viewed 4,762 times
3 Answers
12
Something like this would work (recommend moving the inline CSS to a stylesheet of course):
<div style="position:relative">
<div>
<img src="backgroundimg.png">
</div>
<div style="position:absolute; left:0; top:0;">
<a href="foo.html"><img src="smallgraphic.png"></a>
</div>
</div>
The position:absolute
will place that div relative to a container with position
set, in this case at left 0 top 0. So that means it will end up in the top left of the same element that the 'backgroundimg' is placed in.
Does that make sense?

Ipsquiggle
- 1,814
- 1
- 15
- 25
-
Yes, that makes perfect sense. Thank you! – Ciel Jan 15 '10 at 19:35
-
This is a great solution. Thanks! – Mike Feb 12 '12 at 21:44
-
2Replace attribute "url" by "src". – Andreas Kuckartz Apr 13 '12 at 14:01
1
Don't use more divs than you need.
<div style="position: relative;">
<a style="position: absolute; top: 0; left: 0;">
<img src="..." />
</a>
<img src="..." />
</div>

isaac
- 11
- 1
0
simplify:
<div style="background:url(yourimage.jpg); position:relative;">
<div style="position:absolute; left:0; top:0;">
<a href="somewhere.html"><img src="inner.jpg"></a>
</div>
</div>
or:
<div style="background:url(yourimage.jpg); position:relative;">
<a href="somewhere.html"><img src ="innerimage.jpg" style="position:absolute; left:0; top:0;"/></a>
</div>
or:
<div style="background:url(yourimage.jpg); position:relative;">
<a href="somewhere.html" style="position:absolute; left:0;
top:0;display:block;width:100px;height:100px;"></a>
</div>

dfens
- 5,413
- 4
- 35
- 50
-
If you're setting a background, it's not necessary to set position:absolute, as it will overlap the background in any case. – Ipsquiggle Jan 15 '10 at 23:19