在h1标签语义错误的情况下将h2标签嵌套在另一个标头中? [英] Is nesting a h2 tag inside another header with h1 tag semantically wrong?

查看:276
本文介绍了在h1标签语义错误的情况下将h2标签嵌套在另一个标头中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < h1 class =fixed>是否将h2标签嵌套在另一个标头h1标签内语义错误? 
< h2 class =absolute>
Absolute Div
< / h2>
< / h1>


解决方案

语义错误很大程度上是意见问题语义的意思是与意义有关,但这里的含义是什么?),但构造甚至在语法上(正式)是不正确的。根据所有HTML规范和草案, h1 元素不能包含 h2 元素。



关于小标题或标题的次要部分的标记,关于它的争论很激烈,特别是关于拟议的 hgroup 元素(它可以让你使用 h1 ,后面跟着 h2 ,就好像它是单个标题一样) 。实际的做法一直而且仍然是使用标记,如

 < h1 class =fixed> 
主标题文字< br>
< small class =absolute>
辅助标题文本
< / small>
< / h1>

我已经在这里保存了你的类名,但是他们建议你也许不应该在所有。 h1 元素应该是页面的总标题 h2 元素应该是下一个较低级别的标题,用于页面的顶级部分。


Is nesting a h2 tag inside another header h1 tag semantically wrong?

 <h1 class="fixed">
    <h2 class="absolute">
        Absolute Div
    </h2>
</h1>

解决方案

"Semantically wrong" is largely a matter of opinion ("semantics" means "relating to meaning", but what would be the meaning here?), but the construct isn’t even syntactically (formally) correct. According to all HTML specifications and drafts, an h1 element must not contain an h2 element.

As regards to markup for a "subheading", or a secondary part of a heading, there have been heavy debates on it, especially as regards to the proposed hgroup element (which would let you use h1 followed by h2 as if it were a single heading). The practical approach has been, and still is, to use markup like

<h1 class="fixed">
Primary heading text<br>
<small class="absolute">
Secondary heading text
</small>
</h1>

I have preserved your class names here, but they suggest that perhaps you should not be using heading elements at all. The h1 element is supposed to be the overall heading for the page, and an h2 element is supposed to be a heading at the next lower level, for a top-level section of the page.

这篇关于在h1标签语义错误的情况下将h2标签嵌套在另一个标头中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆