开发者

Text overlays over image using relative positioning

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

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

My problem is, although the text is properly over开发者_StackOverflow社区layed, 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>.


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>


Why not set a div inside the TD set the image to the background of the div and the drop your text in the div?

<td width="10%">
 <div style="background: transparent url("tempballoon.png") no-repeat left top; font-size: 32px;width: 100%; height: height:[height of image]">
  Test
 </div>
</td>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜