0

normally for a html link:

<p><a href="#">this is link</a></p>
<h1><a href="#">this is link</a></h1>
<span><a href="#">this is link</a></span>

Can a href link wrap outside of other element like so?

<a href="#"><p>this is link</p></a>
<a href="#"><h1>this is link</h1></a>
<a href="#"><span>this is link</span></a>

and also outside a div?

<a href="#">
 <div>this is div
     <p>here is the paragraph</p>
     <div>and nested div</div>
 </div>
</a>
Vincent Chua
  • 969
  • 6
  • 20
  • 41

2 Answers2

1

Yes, you could do this. It looks a little odd, but it will work. Take note that in your second example the text will all map to the same link "#".

deweyredman
  • 1,440
  • 1
  • 9
  • 12
1

Yes. There isn't any "prohibited" elements for <a> in the spec (except for the standard <html>, <body>, <head>, <title>, <meta>...). <a> links, and everyone deserves to be linked.

Keep in mind tho that <a> is inline, so you will have to set display: block to use it like <div>

bjb568
  • 11,089
  • 11
  • 50
  • 71