这是一个新手问题。是否可以创建更多的标题样式,如 h7、h8 等。我只是想知道一个网站上是否可以有超过 6 种不同类型的标题。
3 回答
The HTML spec defines 6 headings. Browsers recognize 6 headings. If you start using <h7>
and so on, then you'll be using an invalid element.
If you find yourself needing an <h7>
then you should probably take a look at how you're structuring your site. Not every single title deserves a heading element.
You can create any element you want on a page, but I think your question is whether it will be interpreted correctly by a user agent like a browser. Browsers will allow you to create, apply styles to, and access arbitrarily-created elements on the DOM regardless of whether they conform to the spec implied by your declared DOCTYPE
.
However, in general, it's best to avoid creating deeply nested structures; users find such hierarchies difficult to follow. In addition, as other answers linked in the comments have pointed out, there may be unintended consequences with page accessibility, SEO, or script compatibility. I have yet to find a use case that actually needs such deeply nested hierarchies, except when posting long legal documents as a single HTML page.
一般来说,您可以根据需要创建任意数量的标题,但它们必须定义为类。因此,如果您正在考虑为组织目的制作超过 6 个标题,请执行以下操作:
.h7{
color: #111111;
font-size: 16px;
text-transform: uppercase;
}
<p class="h7"> I'm an extra heading </p>