If block elements are not supposed to go in inline elements, how come we put block elements in anchor (<a>) elements?

huangapple go评论64阅读模式
英文:

If block elements are not supposed to go in inline elements, how come we put block elements in anchor (<a>) elements?

问题

为什么我们要将块元素嵌套在<a>标签内,如果<a>是内联元素,而块元素不应该放在内联元素内部?

我原本期望块元素不会放在<a>标签内,符合指南。

英文:

Why do we nest block elements inside of &lt;a&gt; if &lt;a&gt; is inline and block elements are not supposed to go in inline elements?

I was expecting for block elements to not go in the &lt;a&gt; tag, per the guidelines.

答案1

得分: 3

【内联】和【块】类别是 HTML 4 中组织大多数 HTML 元素的方式。

15 年前,HTML 5 发布了。它更加细致,不仅仅因为它不再试图以 SGML DTD 的形式表达规则。

【a 元素】的内容模型为:

【透明】,但不能有【交互内容】的后代、a 元素的后代,或指定了 tabindex 属性的后代。

这意味着如果 a 元素的父元素允许作为子元素的元素,例如 div 元素,那么a 元素也允许。

英文:

The %inline and %block categories were how HTML 4 organised most elements in HTML.

15 years ago, HTML 5 was released. It is more nuanced, not least because it no longer tries to express the rules in the form of an SGML DTD.

The a element has a content model of:

> Transparent, but there must be no interactive content descendant, a element descendant, or descendant with the tabindex attribute specified.

The means that if the a element's parent allows a (for example) div element as a child, then so does the a element.

huangapple
  • 本文由 发表于 2023年2月24日 05:26:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/75550475.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定