Html h1 标签类(替代)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1725470/
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
h1 tag class (alternate)
提问by menardmam
I know that h1 tag is important for SEO, so all my title is H1 (bravo!)
我知道 h1 标签对 SEO 很重要,所以我所有的标题都是 H1(太棒了!)
Now, I need to have a title (as the first line of a text ) a little different on some pages.
现在,我需要在某些页面上有一个稍微不同的标题(作为文本的第一行)。
Usually, I just duplicate h1 as h2 and alternate.
通常,我只是将 h1 复制为 h2 并交替进行。
The question: Is it possible to add a class to the title tag... (I have try without success)
问题:是否可以在标题标签中添加一个类......(我尝试过但没有成功)
回答by Greg
You can style a header like this:
你可以像这样设置标题:
h1 { color: red; }
Or like this:
或者像这样:
<h1 class="fancy">Fancy</h1>
.fancy { font-family: fantasy; }
If it's not working:
如果它不起作用:
- Check you don't have an old stylesheet cached (ctrl-F5 to reload)
- Check you don't have any rules overriding your class (inspecting with Firebug or similar is very helpful here).
- Check for typos in the HTML and CSS
- 检查您没有缓存旧的样式表(ctrl-F5 重新加载)
- 检查您没有任何覆盖您的类的规则(使用 Firebug 或类似工具进行检查在这里非常有帮助)。
- 检查 HTML 和 CSS 中的拼写错误
Edit:
编辑:
It sounds like you had h1 .myClass
instead of h1.myClass
- there's an important distinction:
听起来你有h1 .myClass
而不是h1.myClass
- 有一个重要的区别:
h1 .myClass { } /* any element with class="myClass" within an <h1> */
h1.myClass { } /* any <h1> with class="myClass" */
回答by Gumbo
Sure you can:
你当然可以:
<h1 class="someclass">…</h1>
The class
attributeis a in the attribute group coreattrsof core attributesthat can be used with the h1
element.
该class
属性位于可与元素一起使用的核心属性的属性组coreattrs中。h1
回答by Guffa
It sounds like you are using h1
for all titles on the page. Typically you would have a single h1
tag on the page for what the page contains (with text at least partly matching the title of the page), and lesser header tags for headlines of different parts of the content. That way you give most information to the search engines about what's important on the page. There are of course pages that doesn't fit into this model, but many do.
听起来您正在h1
为页面上的所有标题使用。通常,您会h1
在页面上为页面包含的内容添加一个标签(文本至少部分与页面标题匹配),以及较少的标题标签用于内容不同部分的标题。这样您就可以向搜索引擎提供有关页面上重要内容的大部分信息。当然有些页面不适合这个模型,但很多都适合。
There are many different ways that you can specify a style for headers. For example:
有许多不同的方法可以指定标题的样式。例如:
For all h1
tags:
对于所有h1
标签:
h1 { font-weight: bold; }
For all h1
and h2
tags:
对于所有h1
和h2
标签:
h1, h2 { margin: 10px; }
For all h1
tags inside an element with id="main"
:
对于h1
元素内的所有标签id="main"
:
#main h1 { background: #ccc; }
For all h2
tags with class="Info"
:
对于所有h2
带有 的标签class="Info"
:
h2.Info { color: #000; }
For all h3
tags inside an element with class="More"
:
对于h3
元素内的所有标签class="More"
:
.More h3 { text-decoration: underline; }
回答by Asaph
You canadd a class to an <h1>
tag. Like this:
您可以将类添加到<h1>
标签。像这样:
<h1 class="myclass"> ... </h1>
You can easily style it like this:
您可以像这样轻松地设置样式:
<style type="text/css">
.myclass { color : green }
</style>
回答by Joseph
The < title > tag is in your < head > section, so it wouldn't really make sense to add a class to it.
< title > 标签在您的 < head > 部分,因此向其中添加类实际上没有意义。
You can add a class to your < h1 > tag, though.
不过,您可以向 < h1 > 标签添加一个类。
<h1 class="title">
回答by user8925959
<div class='row' id='content-wrapper'>
<div class='clear'/>
<b:if cond='data:blog.pageType == "error_page"'>
<div id='error-wrap'>
<h1 class='error-item'>404</h1>
<h2>Page Not Found!</h2>
<p>Sorry, the page you were looking for in this blog does not exist.</p>
<div class='clear'/>
<a class='homepage' expr:href='data:blog.homepageUrl'><i class='fa fa-home'/> Go To Home</a>
</div>
回答by Gus Melo
The following should work:
以下应该工作:
<html>
<head>
<style type="text/css">
h1.custom {
color: red;
font-size: 16px;
}
</style>
</head>
<body>
<h1 class="custom"> test </h1>
</body>
</html>