带有背景图像且无文本的 XHTML 锚链接

发布于 2024-10-12 16:31:17 字数 344 浏览 3 评论 0原文

是否有可能有锚链接,里面没有文字,有背景图像和固定尺寸,并且仍然有利于搜索引擎优化?

CSS 示例:

a{display:block;width:50px;height:20px;background-image:url('images/background.jpg');background-repeat:no-repeat;background-position:0 0;}

a:hover img{background-position:0 -20px;}

HTML 示例:

Is it possible to have anchor links no text inside that has a background image and fixed dimensions and still be good for SEO?

Example CSS:

a{display:block;width:50px;height:20px;background-image:url('images/background.jpg');background-repeat:no-repeat;background-position:0 0;}

a:hover img{background-position:0 -20px;}

Example HTML:
<a href="#"></a>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

江城子 2024-10-19 16:31:17

如果图像中包含文本,或者您只是想添加其描述,您可以做的一件事是帮助 SEO 和可访问性,即为锚点提供带有大负文本缩进的标题和内容,例如将其添加到您的 a CSS:

display:block;
text-indent:-9999em;

...使用以下 HTML:

<a href="#" title="IMAGE TEXT">IMAGE TEXT</a>

If the image has text in it or you simply want to add its description, one thing you can do to help SEO and accessibility is to give the anchor a title and content with a large negative text-indent, like adding this to your a CSS:

display:block;
text-indent:-9999em;

...with the following HTML:

<a href="#" title="IMAGE TEXT">IMAGE TEXT</a>
征棹 2024-10-19 16:31:17

受到 neXib 对另一个答案的评论的启发。

HTML:

<a href="/home" title="Homepage" class="home">
    <div><img src="/images/sprite.png" alt="Home" /></div>
</a>

CSS:

a {
    display: block;
}
.home div {
    width: 84px;
    height: 27px;
    overflow: hidden;
    position: relative;
}
.home div img {
    position: absolute;
    top: -65px;
    left: -20px;
}

只要 div 具有“溢出:隐藏”和固定尺寸,内部图像就可以定位在其中,以仅显示您想要的精灵部分。

SEO 也是我关心的一个问题,我认为这个解决方案会很好用。

Inspired by neXib's comment on another answer.

HTML:

<a href="/home" title="Homepage" class="home">
    <div><img src="/images/sprite.png" alt="Home" /></div>
</a>

CSS:

a {
    display: block;
}
.home div {
    width: 84px;
    height: 27px;
    overflow: hidden;
    position: relative;
}
.home div img {
    position: absolute;
    top: -65px;
    left: -20px;
}

So long as the div has 'overflow: hidden' and fixed dimensions the image inside can be positioned within to only display the part of the sprite you want.

SEO was a concern for me too and I think this solution will work fine.

花期渐远 2024-10-19 16:31:17

搜索引擎看不懂,那对SEO有什么好处呢?更重要的是,你为什么要这样做,你想做什么?

The search engine can't read it, so how would it be good for SEO? More importantly, why do you want to do this, what are you trying to do?

诗酒趁年少 2024-10-19 16:31:17

使用alt和title属性,但是标签内没有内容是没有意义的。我认为你在搜索结果中存在受到惩罚的严重风险!

再说一次,你为什么要尝试这个。您正在制作链接到另一个页面的按钮吗?
运行 JavaScript 函数?

Use alt and title attribute, but having no content inside the tags is pointless.I think that there is a serious risk that you will be penalized in the search results!

Again, why are you trying this. Are you doing buttons that are linking to another page or that
run a javascript function?

如梦亦如幻 2024-10-19 16:31:17

这不就能解决问题吗?

<a href="#"> </a>

嗯,这是一个有点老的问题,但只是想对此发表意见!

Wouldnt this fix the problem?

<a href="#"> </a>

Well this is a bit old question but just want opinion on this!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文