【问题标题】:a href tags on the outside of div tags?div标签外面的href标签?
【发布时间】:2012-08-13 19:18:59
【问题描述】:

我知道 div 标签是大多数标签的容器,例如 href 标签……也就是说,我有一个可以工作的文档,并且只有当 a href 标签围绕两个 div 标签时才起作用。

如果我调整 div 和 href 使其符合 w3c,它会扭曲网站。我可能会调整我的 .js 和 .css 以使其工作,但我想找到一个替代解决方案。我可以将 a 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>

【问题讨论】:

标签: javascript html css xhtml tags


【解决方案1】:

您应该使用 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>

【讨论】:

    【解决方案2】:

    XHTML 2 将允许在任何元素上使用“href”属性,允许块级锚点,并在某些情况下消除相同锚点的重复或在其他情况下消除不必要的附加标签。这真的很有意义,因为“a”标签只是一个跨度,但唯一一个具有附加能力的跨度链接到其他地方。 “a”其实并没有什么特殊的语义含义,页面上的所有链接都可以通过查找带有“href”的标签来解析。在 HTML 5 开发的早期,人们讨论了“随处引用”方法,我很兴奋认为它将成为 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/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-19
      • 1970-01-01
      • 1970-01-01
      • 2015-06-09
      • 1970-01-01
      • 2013-02-04
      • 1970-01-01
      • 2012-05-12
      相关资源
      最近更新 更多