Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XHTML: Placing DIVs in A tags

Tags:

html

anchor

xhtml

Is it alright to place div tags inside anchor tags? Will contents of the div redirect the page to the href of the anchor tag?

like image 574
Francisc Avatar asked Dec 21 '22 23:12

Francisc


1 Answers

Is it alright to place div tags inside anchor tags?

Yes, if:

  1. You are using HTML5/XHTML5; and
  2. The anchor tag is not in an inline context. i.e. a descendant of an element that only allows phrasing content.

Otherwise no.

In HTML5/XHTML5 the <a> element in not simply an inline element as it is in HTML4/XHTML1. Instead it has a transparent content model, which means that the validation rules for its content are the same as if it wasn't there.

So for example

<div>
   <div>Hello World</div>
</div>

is valid, so

<div>
   <a href="#">
      <div>Hello World</div>
   </a>
</div>

is too.

But

<p>
   <div>Hello World</div>
</p>

is not valid, so

<p>
   <a href="#">
      <div>Hello World</div>
   </a>
</p>

isn't either.

like image 174
Alohci Avatar answered Dec 29 '22 10:12

Alohci