Html 可以在同一页面上使用多个 h1 标签,但使用不同的样式吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/503925/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it alright to use multiple h1 tags on the same page, but style them differently?
提问by Brad
I have a webpage that I use h1 tags multiple times within various DIVs and I style h1 for each div to be the appropriate size.
我有一个网页,我在各种 DIV 中多次使用 h1 标签,并且我将每个 div 的 h1 样式设置为适当的大小。
For example...
例如...
#content h1 {
font-size:22px;
}
#left-nav h1 {
font-size:14px;
}
#content .recent-news h1 {
font-size:16px;
}
Is this alright? I am worried about SEO.
这可以吗?我担心 SEO。
What is the best way to go about this? Or am I worrying about nothing?
解决这个问题的最佳方法是什么?还是我什么都不担心?
采纳答案by Treb
In my opinion, you don't need to worry, its ok to do it like this.
在我看来,你不必担心,这样做就可以了。
H1 designates part of your contents to be a first level heading. So if you have a first level heading in your navigation div (e.g. <H1>Navigation Menu</H1>
), of course that should be #nav h1
.
H1 将您的部分内容指定为一级标题。因此,如果您的导航 div(例如<H1>Navigation Menu</H1>
)中有第一级标题,当然应该是#nav h1
.
If you should have several H1s within your contents depends: If you have a blog and every entry has its own heading, those would be H1s. However, if your blog itself has a heading (e.g. <H1>My Blog!</H1>
), the blog entry heading should be an H2.
如果您的内容中应该有多个 H1 取决于:如果您有一个博客并且每个条目都有自己的标题,那么这些将是 H1。但是,如果您的博客本身有标题(例如<H1>My Blog!</H1>
),则博客条目标题应为 H2。
But that is only theory. Go for what is readable, semantic markup. You can best decide on that by looking at your html and asking yourself: 'Is it readable? Would the readability improve if I did it the other way?' The answer will vary from project to project.
但这只是理论。寻找可读的语义标记。您可以通过查看您的 html 并问自己:'它可读吗?如果我以另一种方式这样做,可读性会提高吗?答案因项目而异。
回答by Joel
Matt Cutts from Google answered to More than one H1 on a page: good or bad?(Mar 5, 2009) with:
来自 Google 的 Matt Cutts 回答了一个页面上不止一个 H1:好还是坏?(2009 年 3 月 5 日)与:
Well, if there's a logical reason to have multiple sections, it's not so bad to have, you know multiple
h1
s. I would pay attention to overdoing it. If your entire page ish1
, that looks pretty Creti, right? So don't do allh1
and then you CSS to make it look like regular text because we see people, who are competitors complain about that if users ever turn off CSS or the CSS doesn't load, it looks really bad. So, you know, it's ok to have a little bit ofh1
here and then maybe there's two sections on a page, and so maybe have a little bit ofh1
here.But you really should use it for headers or headings, which is what the intent is. Not to just throw
h1
everywhere you can on a page. Because I can tell you, if you just throwh1
everywhere on a page, people have tried to abuse that and so our algorithms try to take that into account so it doesn't really do you that much good. So I would use it where it makes sense and more sparingly, but you can have it multiple times.
好吧,如果有多个部分是合乎逻辑的,那么拥有多个部分也不错,您知道多个
h1
s。我会注意过度。如果您的整个页面都是h1
,那看起来很漂亮,对吧?所以不要做所有的事情h1
,然后你用 CSS 让它看起来像普通文本,因为我们看到人们,他们是竞争对手,抱怨如果用户关闭 CSS 或 CSS 没有加载,它看起来真的很糟糕。所以,你知道,这里有一点是可以的h1
,然后也许一页上有两个部分,所以也许h1
这里有一点。但是您确实应该将它用于标题或标题,这就是意图。不要只是
h1
在页面上到处乱扔。因为我可以告诉你,如果你只是h1
在页面上到处乱扔,人们会试图滥用它,所以我们的算法会尝试考虑到这一点,所以它对你并没有多大好处。所以我会在有意义的地方更谨慎地使用它,但你可以多次使用它。
回答by Yes - that Jake.
Just remember that your h1s are used to indicate context, not layout. So, there's nothing inherently wrong with having several on a page.
请记住,您的 h1s 用于指示上下文,而不是布局。所以,在一个页面上有几个并没有本质上的错误。
In this specific example, you need to decide if your left-nav h1s have the same contextual importance as your content h1s and your recent-news h1s. If a clear hierarchy exists in your mind, use your header tags to demonstrate it.
在此特定示例中,您需要确定左侧导航 h1 是否与内容 h1 和最近新闻 h1 具有相同的上下文重要性。如果您的脑海中存在清晰的层次结构,请使用标题标签来演示它。
回答by sykora
In general, you should only have one h1 per page, and that h1 should succintly represent the content on that page. As long as you are willing to style with CSS, find out which level of headings (h2, h3, h4, etc) that properly represent the headings you want to use, and then style them instead.
一般来说,每页应该只有一个 h1,并且 h1 应该简洁地表示该页面上的内容。只要您愿意使用 CSS 进行样式设置,请找出可以正确表示您要使用的标题的标题级别(h2、h3、h4 等),然后为它们设置样式。
回答by ern
Semantically, I prefer using one h1 on the page, mainly for the title of the page. It probably doesn't matter too much with SEO, and with the way html is going with HTML5, the generic header
tag will make it much simpler and this argument obsolete.
在语义上,我更喜欢在页面上使用一个 h1,主要用于页面的标题。对于 SEO,这可能无关紧要,并且随着 html 与 HTML5 的结合,通用header
标签将使它变得更简单,并且这个论点已经过时。
回答by aalaap
I don't like the idea of multiple H1
s. H1
is the top level, most important heading and the page will basically be about that topic. If you have an equally important second topic, don't put it in another H1
tag, just put it in another page. It deserves that, right?
我不喜欢多个H1
s的想法。H1
是顶级、最重要的标题,页面基本上是关于该主题的。如果你有一个同样重要的第二个主题,不要把它放在另一个H1
标签中,只需将它放在另一个页面中。这是应得的,对吧?
回答by Tab Petree
I try to have only one H1 on the page and have it almost but slightly re-arranged from the content of the title tag / H1 is the the main idea of an individual page every thing else should be an h2 tag and Lower....
我尝试在页面上只有一个 H1,并根据标题标签的内容对其进行了几乎但略微重新安排/H1 是单个页面的主要思想,其他所有内容都应该是一个 h2 标签,而更低... .
回答by seo header tags
If it is regarding seo it's better to use h1 tags And If you want to use it for just sytling purpose use css stylesheets.
如果是关于 seo,最好使用 h1 标签,如果您只想将它用于设计目的,请使用 css 样式表。
The most important is that: If more then one h1 tag is used in a webpage then google may consider that page as spam. use can other heading tags other than h1 like h2 h3 h4 h5 h6 any number of times.
最重要的是:如果网页中使用了多个 h1 标签,那么 google 可能会将该网页视为垃圾邮件。可以使用 h1 以外的其他标题标签,如 h2 h3 h4 h5 h6 任意次数。
回答by seo header tags
It all depends a bit on what your doctype
is. With html5
it's OK to use multiple h1
tags per section. (don't read, per <section></section>
!)
When using in example the XHTML 1.0 Transitional
doctype
, I'd avoid using multiple h1
tags on a single page.
这一切都取决于你doctype
是什么。随着html5
它的正常使用多个h1
每部分标签。(不要阅读,每<section></section>
!)在示例中使用时XHTML 1.0 Transitional
doctype
,我会避免h1
在单个页面上使用多个标签。
When using in example the XHTML 1.0 Transitional
doctype
, I'd often go for something like this:
在示例中使用时XHTML 1.0 Transitional
doctype
,我经常会这样做:
- h1 : max. one time per page
- h2 : max. two times per page
- etc.
- h1:最大。每页一次
- h2:最大。每页两次
- 等等。
Also @joel, even though your answer is sort of OK, please don't try to confuse anyone... I can say I'm a Google software engineer, because I simply work with Google (not the company, but the product) AND I'm an engineer... Please list your company name AND any certifications when claiming things as such.
还有@joel,即使你的回答还不错,但请不要试图混淆任何人......我可以说我是一名谷歌软件工程师,因为我只是与谷歌合作(不是公司,而是产品)而且我是一名工程师...在声明此类内容时,请列出您的公司名称和任何认证。
回答by Charles Addis
I think its good SEO practice to place an H1 tag at the top of every block element on my page, but thats just me. Of course this H1 tag should contain information relevant to the keywords/topics you are targeting.
我认为在我页面上每个块元素的顶部放置一个 H1 标签是一种很好的 SEO 实践,但这只是我。当然,此 H1 标签应包含与您定位的关键字/主题相关的信息。
This is a very effective SEO method I have found, so the people telling you not to do this are trying to keep you from joining in on our winnings.
这是我发现的一种非常有效的 SEO 方法,因此告诉您不要这样做的人试图阻止您加入我们的奖金。