简体   繁体   English

HTML语义:将链接(锚元素)放在标题中是一个好主意吗?

[英]HTML semantics: Is it a good idea to put links (anchor elements) in headings?

Is that wrong to build news list this way: 以这种方式构建新闻列表是错误的:

   <h1><a href="article-1.html">That happened!</a></h1>
   <div class="short">Just like planned</div>

Should I prefer this? 我喜欢这个吗?

   <h1>That happened!</h1>
   <div class="short">Just like planned</div>
   <div><a href="article-1.html">Read it now</a></div>

or remove header elements? 或删除标题元素?

   <div class="news-header"><a href="article-1.html">That happened!</a></div>
   <div class="short">Just like planned</div>

It's perfectly valid to put a link inside a heading. 将链接放在标题内是完全有效的。 In fact, Stack overflow even does it on every question page. 实际上,Stack溢出甚至会在每个问题页面上执行。 Do whatever makes most semantic sense for the page. 做任何对页面最具语义意义的事情。

In HTML5, you can even wrap the heading inside the link, like so: 在HTML5中,您甚至可以将标题包装在链接中,如下所示:

<a href="article-1.html"><h1>That happened!</h1></a>

It is syntactically valid to put anchors inside headings. 将锚点放在标题内部在语法上是有效的。

Your first example: H1 should contain the page heading such as "News". 您的第一个示例: H1应包含页面标题,例如“新闻”。 The "list" of news items you should use a sub-heading ( H2 ). 新闻项目的“列表”应使用子标题( H2 )。 On the "details" page you can put the news title in H1 . 在“详细信息”页面上,您可以将新闻标题放在H1

Your second example: it is valid but not good as far as SEO is concerned. 你的第二个例子:就SEO而言,它是有效但不好的。 Links that contain text such as "read more", "click here" etc do not tell the search engine what the link is about. 包含诸如“阅读更多”,“点击此处”等文本的链接不会告诉搜索引擎该链接是什么。

Your third example: it is valid and reasonably good for SEO. 你的第三个例子:它对SEO有效且合理。 But note that the weight of the words used inside heading and bold tags is considered higher by search engines. 但请注意,搜索引擎认为标题和粗体标签内使用的单词的权重更高。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM