【问题标题】:html link correct placement?html链接正确放置?
【发布时间】:2013-11-18 12:37:58
【问题描述】:

通常用于 html 链接:

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

href 链接可以像这样包裹在其他元素之外吗?

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

还有在 div 之外?

<a href="#">
 <div>this is div
     <p>here is the paragraph</p>
     <div>and nested div</div>
 </div>
</a>

【问题讨论】:

标签: html hyperlink anchor href


【解决方案1】:

是的。规范中没有针对 &lt;a&gt; 的任何“禁止”元素(除了标准的 &lt;html&gt;&lt;body&gt;&lt;head&gt;&lt;title&gt;&lt;meta&gt;...)。 &lt;a&gt; 链接,每个人都值得被链接。

请记住 &lt;a&gt; 是内联的,因此您必须设置 display: block 才能像 &lt;div&gt; 一样使用它

【讨论】:

    【解决方案2】:

    是的,你可以这样做。它看起来有点奇怪,但它会起作用。请注意,在您的第二个示例中,文本将全部映射到同一个链接“#”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-26
      • 1970-01-01
      • 1970-01-01
      • 2018-11-24
      • 1970-01-01
      • 2013-02-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多