Semantically, which is more correct: a in h2, or h2 in a?

后端 未结 5 427
栀梦
栀梦 2020-11-30 05:40

I\'m stuck deciding which to use as both seem to work.

Should I be placing links inside of

elements?

Or the ot

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 05:46

    The W3C specs for h2 say that its permitted parent elements are anything that can contain flow elements, or hgroups. The specs for a permit parent elements that can contain phrasing or flow elements. h2 can contain phrasing content, and a can contain phrasing or flow content, so based on the spec it appears that either is permitted.

    Since you included the semantics tag, I assume you're interested in which 'seems' better too. For my part, since I can't think of when I'd want an anchor to span a heading plus other content, but I can think of plenty of times when a header should contain an anchor plus other content, a inside h2 seems the best route to go.

提交回复
热议问题