第一种方法、添加一个DIV,采用绝对定位,图片所属DIV为基准。
参考代码如下:
1
2
3
4
5
6
<div style="position:relativewidth:100pxheight:100px">
<img src="" alt="" />
<div style="position:absolutewidth:100pxheight:100pxz-indent:2left:0top:0">
文字
</div>
</div>
第二种方法、图片作为背景图片。
参考代码如下:
1
2
3
<div style="background:url(abc.jpg) no-repeat left top">
文字
</div>
这是因为右边的图片边框压住了左边的图片边框。边框值设置的是1px,margin-left:-1,向左移动1px就可以了。
如果盒子都没有加定位,可以鼠标悬浮时,给盒子加上相对定位relative属性。因为相对定位的盒子会压住普通盒子,位置没有设置偏移量的话就不会动。