在css样式里面给背景图片加连接

html-css09

在css样式里面给背景图片加连接,第1张

直接在图片的img的属性onclick上写上"window.open("你的url地址")",这样就可以点击图片在新窗口中打开链接。如果你想在当前页面中打开,就直接用window.location.href=“你的链接”,然后就可以了。

本末倒置,是给链接加背景图:

<a id="caidanbg" href="hxjs.asp">链接</a>

#caidanbg{

display: block

width:180px

height:43px

background:url(../images/hxjsan1.jpg) no-repeat

text-indent: -99999em

}

css是无法加超链接的,但是你可以在一个A标签下设置背景图片啊。

.a{background:url(../images/v_line2.gif)

0

0

no-repeatwidth:100pxheight:30pxdisplay:block}

............

<a

href="xxx.html"

class="a"></a>

这样就OK了但是一定要注意设置display属性为block

或者inline-block才能有点击区域,不然<a></a>之间就要插入一张透明图片设置宽高如<a

href="xxx.html"

class="a"><img

src="透明图片地址"

width="100"

height="30"></a>