如何以符合标准的方式链接标题?

问题描述:

我有HTML块,看起来像这样:如何以符合标准的方式链接标题?

<div id="header"> 
    <h1>title</h1> 
    <h2>subtitle</h2> 
</div> 

我使用一个CSS技术来隐藏所有文字和用图像替换它。但我想将整个区块链接到主页。我不能将它包装在<a>中,因为这不符合标准。那我该怎么做呢?


我的解决方案;通过New in town

<div id="header"> 
    <h1>title</h1> 
    <h2>subtitle</h2> 
    <a href="index.html">Home</a> 
</div> 

#header { 
    text-indent: -9999px; 
    width: 384px; 
    height: 76px; 
    background: transparent url(../images/header.png) no-repeat; 
    margin: 10px; 
    position: relative; 
} 

#header a { 
    display: block; 
    width: 100%; 
    height: 100%; 
    position: absolute; 
    top: 0; 
    left: 0; 
} 

将链接元素放在标题div之外,并使用绝对定位覆盖它们。还要添加一个z-index以确保链接接收用户输入。

<style> 
    a.header 
    { 
     position: absolute; 
     display: block; 
     width: 100%; 
     height: 100px; 
     z-index: 1; 
    } 
</style> 

<div id="header"> 
     <h1>title</h1> 
     <h2>subtitle</h2> 
</div> 

<a href="homepage" class="header"></a> 
+0

我猜这个主意很好,但我认为你的语义是错误的。 ''标签中应该有文字,如果您也在标头中投掷'',则可能更容易处理。 – mpen 2009-09-19 23:01:47

覆盖链接到网页上的所有顶部完全透明的图像启发?