2009-11-12 71 views
2

我知道,h1标签是搜索引擎优化的重要,所以我所有的标题是H1(好样的!)h1标签类(备用)

现在,我需要有一个标题(如文本的第一行)在一些页面上有点不同。

通常,我只是复制h1作为h2和备用。

的问题是:是否有可能一个类添加到标题标签...(我已经尝试没有成功)

+0

请发表您的代码或网址。 – Asaph 2009-11-12 21:19:22

+0

我已经尝试跨度,但它爬上边缘/填充 – menardmam 2009-11-12 21:20:16

回答

2

可以类添加到<h1>标签。就像这样:

<h1 class="myclass"> ... </h1> 

您可以轻松风格像这样:当然

<style type="text/css"> 
.myclass { color : green } 
</style> 
0

<标题>标记位于您的< head>部分中,所以向它添加类是没有意义的。

不过,您可以将类添加到您的< h1>标记中。

<h1 class="title"> 
14

您可以风格像这样的标题:

h1 { color: red; } 

或者这样:

<h1 class="fancy">Fancy</h1> 

.fancy { font-family: fantasy; } 

如果它不工作:

  • 检查你没有一个旧的样式表缓存(ctrl-F5重新加载)
  • 检查你没有任何规则覆盖你的班级(使用Firebug或类似的检查在这里非常有帮助)。
  • 检查在HTML和CSS错别字

编辑:

这听起来像你有h1 .myClass,而不是h1.myClass - 有一个重要的区别:

h1 .myClass { } /* any element with class="myClass" within an <h1> */ 
h1.myClass { } /* any <h1> with class="myClass" */ 
0

下面应该工作:

<html> 
<head> 
<style type="text/css"> 
h1.custom { 
    color: red; 
    font-size: 16px; 
} 
</style> 
</head> 
<body> 

<h1 class="custom"> test </h1> 
</body> 
</html> 
4

I听起来就像你在页面上使用h1的所有标题。通常,页面上会包含一个h1标签,其中包含文本至少部分与页面标题匹配的内容,以及内容不同部分标题的较小标题标签。这样,您可以向搜索引擎提供有关页面上重要内容的大部分信息。当然有些页面不适合这种模式,但很多都可以。

有许多不同的方法可以为标题指定样式。例如:

对于所有h1标签:

h1 { font-weight: bold; } 

对于所有h1h2标签:

h1, h2 { margin: 10px; } 

对于元件内部的所有h1标签与id="main"

#main h1 { background: #ccc; } 

全部h2个标签与class="Info"

h2.Info { color: #000; } 

一个元素内的所有h3标签与class="More"

.More h3 { text-decoration: underline; } 
0

<div class='row' id='content-wrapper'> 
    <div class='clear'/> 
    <b:if cond='data:blog.pageType == &quot;error_page&quot;'> 
    <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> 
+3

添加一些解释并回答这个答案如何帮助OP修复当前问题 – 2017-11-11 22:39:05