In HTML which way round should and

be nes

2019-03-25 09:02发布

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>

标签: html xhtml
3条回答
趁早两清
2楼-- · 2019-03-25 09:14

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).

查看更多
Juvenile、少年°
3楼-- · 2019-03-25 09:14

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/

查看更多
祖国的老花朵
4楼-- · 2019-03-25 09:24

this is the right answer:

<h1><a href="www.example.com">Example!</a></h1>
查看更多
登录 后发表回答