문제

I have weird problem with wrapping anchor tag around div in php because anchor goes inside div. Here is code:

$output .= '<a href="http://google.com">';
$maplist = implode(', ', array_values($rounds));
$output .= '<div class="maplist">' . $maplist . '</div>';
$output .= '</a>';

echo $output;

Html shows like this

 <div class="maplist"><a href="http://google.com"></a>
   <a title="cs_assault" href="link1">cs_assault</a>, 
   <a title="de_aztec" href="link2">de_aztec</a>
   </div>

instead of

<a href="http://google.com">
   <div class="maplist">
   <a title="cs_assault" href="link1">cs_assault</a>, 
   <a title="de_aztec" href="link2">de_aztec</a>
   </div></a>

Weird part is when I remove implode function it outputs like it should.

도움이 되었습니까?

해결책

Nested anchor tags are illegal in HTML 4: http://www.w3.org/TR/html401/struct/links.html#h-12.2.2

Any interactive content cannot be nested in HTML 5: http://www.w3.org/html/wg/drafts/html/master/single-page.html#the-a-element A link counts as an "interactive" element.

다른 팁

You could change the .output to include the link in your div:

$output .= '<div class="maplist" onclick="location.href='http://google.com';">' . $maplist . '</div>';

This should work fine, unless of course you wanted to avoid javascript.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top