如何以符合标准的方式链接标头?
我有一个 HTML 块,如下所示:
<div id="header">
<h1>title</h1>
<h2>subtitle</h2>
</div>
我使用 CSS 技术来隐藏所有文本并将其替换为图像。但我想将整个块链接到主页。我无法将其包装在 中,因为这不符合标准。那么我该怎么做呢?
我的解决方案;灵感来自城镇新事物
<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;
}
I have a block of HTML that looks like this:
<div id="header">
<h1>title</h1>
<h2>subtitle</h2>
</div>
I'm using a CSS technique to hide all that text and replace it with an image. But I want to link the whole block to the homepage. I can't wrap it in <a>
because that wouldn't be standards-compliant. So how do I do it?
My solution; inspired by 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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将链接元素放在标题 div 之外,并使用绝对定位使其覆盖它们。还要添加 z 索引以确保链接接收用户输入。
Put a link element outside of the header divs and make it cover them by using the absolute positioning. Also add a z-index to make sure the link receives user input.
在所有链接到主页的内容上覆盖一个完全透明的图像?
Overlay a completely transparent image on top of it all that is linked to the homepage?