如何在一个声明中指定所有H1-H6标题字体属性?

时间:2013-07-23 23:37:12

标签: html css html5 xhtml

如何在一个声明中指定所有H1-H6标题字体属性? CSSLint.net还显示警告标题应该只定义一次。我有一些指定标题的地方:

h1 { font-size: 1.8em; margin-top: 2em; margin-bottom: .5em; }
h2 { font-size: 1.6em; margin-top: 2em; margin-bottom: .5em; }
h3 { font-size: 1.4em; margin-top: 1.5em; margin-bottom: .5em; }
h4 { font-size: 1.2em; margin-top: 1.2em; margin-bottom: .3em; }
h5 { font-size: 1.1em; margin-top: 1em; margin-bottom: .1em; }
h6 { font-size: 1.0em; margin-top: 1em; margin-bottom: .1em; }

h1, h2 {
padding-bottom:2px;
border-bottom:1px solid #919699;
}

h1, h2, h3, h4, h5, h6 {
font-weight:bold;
line-height:normal;
}

2 个答案:

答案 0 :(得分:2)

简单...所有网站都说不是一遍又一遍地声明相同的标签......使用这样的东西......

h1 { font-size: 1.8em; margin-top: 2em; margin-bottom: .5em;
padding-bottom:2px;
border-bottom:1px solid #919699;
font-weight:bold;
line-height:normal;}
h2 { font-size: 1.6em; margin-top: 2em; margin-bottom: .5em;
padding-bottom:2px;
border-bottom:1px solid #919699;
font-weight:bold;
line-height:normal;}
h3 { font-size: 1.4em; margin-top: 1.5em; margin-bottom: .5em; 
font-weight:bold;
line-height:normal;}
h4 { font-size: 1.2em; margin-top: 1.2em; margin-bottom: .3em;
font-weight:bold;
line-height:normal;}
h5 { font-size: 1.1em; margin-top: 1em; margin-bottom: .1em; 
font-weight:bold;
line-height:normal;}
h6 { font-size: 1.0em; margin-top: 1em; margin-bottom: .1em;
font-weight:bold;
line-height:normal;}

显然,你的方式稍微有点可读......但这会巩固一切,所以每个标签只定义一次。

答案 1 :(得分:1)

你的榜样很好。他们的意思是你应该只在HTML中使用一次h1标题,但后来改变了。 W3C标准现在允许您使用任意多个。他们实际上鼓励它,为SEO。