2012-08-13 223 views
0

据我所知,div标签是大多数标签的容器,例如href标签......这就是说我有一个可以工作的文档,只有当href标签是围绕两个div标签时才起作用。div标签外部的href标签?

如果我调整div和一个href使它符合w3c,它会扭曲网站。我可以调整我的.js和.css文件以使其正常工作,但我希望找到一种替代解决方案。我可以将href标签保留在现在的位置吗?

感谢您的任何帮助或建议。

链接在这里:http://momentum.freeiz.com/

代码这里:

<a href="hapo.htm" >   
    <div class="boxgrid_slideright"> 
    <div id="slideshow"> 
     <img class= "cover" src="images/home/ hapo/0.jpg" width="161" height="107" alt="hapo credit union"/> 
     <img class= "cover" src="images/home/ hapo/1.jpg" width="161" height="107" alt="hapo credit union"/> 
     <img class= "cover" src="images/home/ hapo/2.jpg" width="161" height="107" alt="hapo credit union"/> 
     <img class= "cover" src="images/home/ hapo/3.jpg" width="161" height="107" alt="hapo credit union"/> 
     <img class= "cover" src="images/home/ hapo/4.jpg" width="161" height="107" alt="hapo credit union"/> 
    </div><!--slideshow--> 
    </div><!--boxgrid--> 
</a> 
+0

我想我的代码没有露面,这里是链接:http://momentum.freeiz.com/ – magX 2012-08-13 19:20:34

+4

如果您将'div'元素更改为'span'元素,那么您将嵌套内联元素,这是允许的。 – 2012-08-13 19:22:27

回答

3

你应该风格的行内元素表现为与CSS块元素:

CSS:

a.whatever, .boxgrid_slideright, .slideshow { 
    display: block; 
} 

HTML:

<a class="whatever" href="hapo.htm" >   
    <span class="boxgrid_slideright"> 
    <span id="slideshow"> 
     <img class= "cover" src="images/home/ hapo/0.jpg" width="161" height="107" alt="hapo credit union"/> 
     <img class= "cover" src="images/home/ hapo/1.jpg" width="161" height="107" alt="hapo credit union"/> 
     <img class= "cover" src="images/home/ hapo/2.jpg" width="161" height="107" alt="hapo credit union"/> 
     <img class= "cover" src="images/home/ hapo/3.jpg" width="161" height="107" alt="hapo credit union"/> 
     <img class= "cover" src="images/home/ hapo/4.jpg" width="161" height="107" alt="hapo credit union"/> 
    </span><!--slideshow--> 
    </span><!--boxgrid--> 
</a> 
0

XHTML 2将允许在任何元素上使用“href”属性,从而允许块级锚定,并且在某些情况下可以消除同一个锚点的重复或其他不必要的附加标记。这确实有道理,因为“a”标签只是一个跨度,但是只有一个跨度能够链接到其他地方。对于“a”实际上没有特殊的语义含义,并且通过使用“href”查找标签可以在解析中找到页面上的所有链接。在HTML 5开发的早期,讨论了“href anywhere”方法,我很兴奋地认为它将成为HTML 5的一部分。当时,这是关于HTML 5最有趣的事情,对我来说。但“任何地方的href”都意味着所有先前的浏览器根本无法看到链接(除了出于某种原因放入“a”标签的链接),所以这个想法被废弃了。相反,HTML 5创作者利用了当前浏览器已具备的反对规格功能:块级锚点。浏览器至少回到IE 6会很高兴地将“流量内容”放在一个“a”标签中成为一个链接。 via - 托比·麦肯齐

http://davidwalsh.name/html5-elements-links

http://html5doctor.com/block-level-links-in-html-5/

+0

@托比,感谢您的洞察力 – magX 2012-08-13 19:51:28