Text overlays over image using relative positioning

Water picture Water · Sep 17, 2011 · Viewed 44.1k times · Source

I want to position a text overlaying an image. Below is my currently used code:

My problem is, although the text is properly overlayed, the "space" it consumes in the <td> is still there! When I tried to replace the 'top' position in the <div> with 'margin-top', it also affects the <img> and so the <img> goes past the border of the <td>.

Answer

Blender picture Blender · Sep 17, 2011

You want position: absolute and the container to be relative:

<td width="10%" style="position: relative;">
    <img src="tempballoon.png" alt="balloon"  style="z-index: -1"/>
    <div style="position:absolute;left:0px;top:0px;font-size: 32px;display: none">
      Test
    </div>
</td>