In HTML which way round should <a/> and <h1/> be nested?

跟風遠走 提交于 2019-12-04 17:28:01

问题


Is there a more correct order for nesting a <a> and <h1> elements in HTML?

e.g.:

<a href="www.example.com"><h1>Example!</h1></a>

or

<h1><a href="www.example.com">Example!</a></h1>

回答1:


In HTML 4.01 and XHTML 1.1 and older:

  • An h1 may contain an a
  • An a may not contain an h1

So <h1><a>…</a></h1>

In the HTML 5 draft:

  • An h1 may contain an a
  • An a may contain an h1 (but only if the a is somewhere an h1 is allowed — see the comments on this answer)

So either, but browser support may vary (such is life on the bleeding edge).




回答2:


this is the right answer:

<h1><a href="www.example.com">Example!</a></h1>



回答3:


HTML4, XHTML

<h1><a href="">Text</a></h1>

HTML5

<h1><a href="">Text</a></h1>
<a href=""><h1>Text</h1></a>

It's acceptable in HTML5 as the anchor tag's been made 'block level'.

Some good info on block level and inline level tags can be found at http://www.webdesignfromscratch.com/html-css/css-block-and-inline/



来源:https://stackoverflow.com/questions/5080261/in-html-which-way-round-should-a-and-h1-be-nested

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!