简体   繁体   English

DL内部的H1,H2等有效吗?

[英]Are H1, H2 etc valid inside DLs?

Can I have heading elements inside definition lists? 定义列表中可以包含标题元素吗?

Example: 例:

<dl>
 <h4> heading </h4>

 <dt> title </dt> <dd> content </dd>
 <dt> title </dt> <dd> content </dd>
 <dt> title </dt> <dd> content </dd>

 <h4> heading </h4>

 <dt> title </dt> <dd> content </dd>
 <dt> title </dt> <dd> content </dd>
 <dt> title </dt> <dd> content </dd>

</dl>

It seems to work as expected in my browser :) 它似乎可以在我的浏览器中正常工作:)

No; 没有; the only elements that might be valid within a dl are dd and dt . dl中可能唯一有效的元素是dddt

The reason it may appear to work is error handling by the browser, which is both unpredictable and, so far as I can tell, mostly undocumented and therefore should not be relied upon. 它可能会出现工作的原因是由浏览器,这既是不可预测的,所以据我所知,大多无证,因此不应依赖该等资料错误处理。

Though interestingly, as Šime Vidas notes in the comments (below), Firefox, Chrome, Safari, Opera and Internet Explorers 7 and 9 don't correct the structure and allows the heading elements to remain within the dl . 有趣的是,正如ŠimeVidas在评论中(以下)所述,Firefox,Chrome,Safari,Opera和Internet Explorer 7和9不会更正结构,并允许标题元素保留在dl Which strikes me as being weird. 这让我感到奇怪。

It is, though, while tolerated, still invalid. 虽然可以容忍,但仍然无效。 Whether or not you choose to respect that validity is, of course, optional. 当然,是否选择尊重有效性是可选的。

References: 参考文献:

FWIW, you can use the w3c markup validator in direct input mode to check code snippets. FWIW,您可以在直接输入模式下使用w3c标记验证器来检查代码段。

Browsers are VERY tolerant of bad html, and not conforming to the rules, even though it works now, might mean your page/layout breaks with a future browser update. 浏览器可以很好地容忍错误的html,并且即使现在可以正常工作也不符合规则,这可能意味着您的页面/布局可能会因将来的浏览器更新而中断。

I added the required other elements to get your code to validate as noted below. 我添加了必需的其他元素,以使您的代码通过验证,如下所述。 Complains about exactly what David Thomas says. 抱怨大卫·托马斯(David Thomas)所说的话。

  <!DOCTYPE html> <html> <head> <title>asdf</title> </head> <body> <dl> <h4> heading </h4> <dt> title </dt> <dd> content </dd> <dt> title </dt> <dd> content </dd> <dt> title </dt> <dd> content </dd> <h4> heading </h4> <dt> title </dt> <dd> content </dd> <dt> title </dt> <dd> content </dd> <dt> title </dt> <dd> content </dd> </dl> </body> </html> 

you could add 2 dt tags one with a class 您可以在一个类中添加2个dt标签

 dt.heading { font-weight: bold } 
 <dl> <dt class="heading">Heading</dt> <dt>milk</dt> <dd>white discharge</dd> </dl> 

lets you have multiple after each other since multiple terms can have the similar if not the same definition. 可以让您一个接一个的定义,因为如果定义不相同,则多个术语可以具有相似的含义。 like wise you can have multiple since a term can have a few different meanings. 明智的做法是,您可以有多个,因为一个术语可以有几种不同的含义。 And even thou you are changing the way it looks via CSS this wont be a true Heading and will porb get skipped by search engines etc... maybe have a hidden h1 tag with seo content 即使您正在更改通过CSS的外观,也不会是真正的标题,并且搜索引擎等会跳过porb的问题……也许有带有SEO内容的隐藏的H1标签

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM