我有HTML块看起来像这样:

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

我使用CSS技术来隐藏所有文本和与图像替换它。但我想整个块链接到主页。我不能在<a>包装它,因为那会不会是符合标准的。所以,我怎么办呢?


我的解决办法;在镇由新功能

<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索引以确保链路接收用户输入。

<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>

其他提示

上链接到主页的所有顶部覆盖层完全透明的图像?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top