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

html-css08

在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

}

为a标签添加一个背景就可以了

a{

width: 20px

height: 18px

background: url(images)

display: inline-block

}

宽和高是必须的,因为使用背景图片是需要宽高的