如何在超链接中显示图片而不是文本?请看我的示例,您可以看到文本“x”和背景图像。我只想显示超链接的背景图像。
.cancel {
background: url(http://www.softicons.com/download/web-icons/light-grey-square-icons-by-axialis-team/png/16/Cancel.png) center no-repeat;
text-indent: -9999px;
display: block;
width: 16px;
height: 16px;
}
将链接的display: block;
设置为块级元素,这样您可以给它设置与背景图片相同的宽度和高度,然后使用text-indent
隐藏实际文本。
<a href="" class="cancel" title="Cancel"><span>X</span></a>
.cancel span {display:none}
将链接中的 x 删除(并替换为空格)
<a href="" class="cancel" title="Cancel"> </a>
将你的CSS更改为:
.cancel{
width:58px; /* width of image */
height:58px; /* height of image */
display:block; /* block so always the whole image will be shown */
background:url(http://www.softicons.com/download/web-icons/light-grey-square-icons-by-axialis-team/png/16/Cancel.png) center no-repeat;
}
不要把文本放在 <a> </a>
标签之间,而是放一个 <img>
<a href="" class="cancel" title="Cancel">
<img src="http://www.softicons.com/download/web-icons/light-grey-square-icons-by-axialis-team/png/16/Cancel.png" />
</a>
<p>Create a link of an image:
<a href="#">
<img src="smiley.gif" width="32" height="32" />
</a>
看这个简单的例子 http://www.w3schools.com/HTML/tryit.asp?filename=tryhtml_imglink
text-indent: -9999px;
究竟是做什么的吗? - sunjie