它在 HTML5 中被声明为有效,因为它对元素的定义a
具有“透明”内容模型。因此,当一个a
元素出现在允许的上下文中时h3
,则a
允许该元素包含一个h3
元素。
这偏离了 HTML 4.01 规范,其中允许a
元素仅具有“内联”内容(例如,没有标题)。所有以前的 HTML 规范都采取相同的立场。
However, browsers actually let you nest h3
inside a
, too, so HTML5 is effectively just echoing browser practice. Note, however, that there is a functional difference: you can see this by clicking on some point to the right of the heading text. (The reason is that if you nest h3
inside a
, the link takes the full available width, extending past the text.)
Any CSS settings are immaterial here. HTML validity does not depend on them, or even on the existence of CSS.