用徽标图像替换 H1 文本:搜索引擎优化和可访问性的最佳方法? [英] Replacing H1 text with a logo image: best method for SEO and accessibility?
问题描述
似乎有几种不同的技术,所以我希望得到一个确定性"的答案......
在网站上,通常的做法是创建一个链接到主页的徽标.我想做同样的事情,同时针对搜索引擎、屏幕阅读器、IE 6+ 以及禁用 CSS 和/或图像的浏览器进行最佳优化.
示例一:不使用 h1 标签.不太适合 SEO,对吧?
<a href=""><img src="logo.png" alt="堆栈溢出"/></a>
示例二: 在某处找到了这个.CSS 看起来有点笨拙.
<a href="">Stack Overflow</a>
/* css */#标识 {填充:70px 0 0 0;溢出:隐藏;背景图片:网址(logo.png");背景重复:不重复;高度:0px!重要;高度/**/:70px;}
示例三: 相同的 HTML,使用文本缩进的不同方法.这是图像替换的Park"方法.
<a href="">Stack Overflow</a>
/* css */#标识 {背景:透明 url("logo.png") 无重复滚动 0% 0%;宽度:250px;高度:70px;文本缩进:-3333px;边框:0;边距:0;}#logo a {显示:块;宽度:280px;/* 比实际图像大?*/高度:120px;文字装饰:无;边框:0;}
示例四: Leahy-Langridge-杰弗里斯方法.在关闭图像和/或 css 时显示.
<a href="">Stack Overflow</a>
/* css */h1.logo {边距顶部:15px;/* 对于这个特定的站点,根据需要进行设置 */位置:相对;/* 允许将子元素放置在这个位置上 */溢出:隐藏;/* 不要让内容泄漏到标题之外 - 不需要,因为锚的高度将覆盖整个标题 */填充:0;/* 需要对抗重置/默认样式 */}h1.logo a {位置:绝对;/* 默认为 top:0, left:0,所以这些可以省略 */高度:0;/* 隐藏文本,防止它出现峰值 */宽度:100%;/* 686 像素;填充父元素 */背景位置:左上角;背景重复:不重复;}h1#logo {高度:60px;/* 替换图像的高度 */}h1#logo a {填充顶部:60px;/* 替换图像的高度 */背景图片:网址(logo.png");/* 替换图像 */}
什么方法最适合这种事情?请在答案中提供 html 和 css.
您缺少选项:
<a href="http://stackoverflow.com"><img src="logo.png" alt="堆栈溢出"/></a>
h1 和 img 中的标题非常非常重要!
It seems like there are a few different techniques out there, so I was hoping to get a "definitive" answer on this...
On a website, it's common practice to create a logo that links to the homepage. I want to do the same, while best optimizing for search engines, screen readers, IE 6+, and browsers who have disabled CSS and/or images.
Example One: Doesn't use an h1 tag. Not as good for SEO, right?
<div id="logo">
<a href="">
<img src="logo.png" alt="Stack Overflow" />
</a>
</div>
Example Two: Found this somewhere. The CSS seems a little hacky.
<h1 id="logo">
<a href="">Stack Overflow</a>
</h1>
/* css */
#logo {
padding: 70px 0 0 0;
overflow: hidden;
background-image: url("logo.png");
background-repeat: no-repeat;
height: 0px !important;
height /**/:70px;
}
Example Three: Same HTML, different approach using text-indent. This is the "Phark" approach to image replacement.
<h1 id="logo">
<a href="">Stack Overflow</a>
</h1>
/* css */
#logo {
background: transparent url("logo.png") no-repeat scroll 0% 0%;
width: 250px;
height: 70px;
text-indent: -3333px;
border: 0;
margin: 0;
}
#logo a {
display: block;
width: 280px; /* larger than actual image? */
height: 120px;
text-decoration: none;
border: 0;
}
Example Four: The Leahy-Langridge-Jefferies method. Displays when images and/or css is turned off.
<h1 id="logo" class="logo">
<a href="">Stack Overflow</a>
</h1>
/* css */
h1.logo {
margin-top: 15px; /* for this particular site, set this as you like */
position: relative; /* allows child element to be placed positioned wrt this one */
overflow:hidden; /* don’t let content leak beyond the header - not needed as height of anchor will cover whole header */
padding: 0; /* needed to counter the reset/default styles */
}
h1.logo a {
position: absolute; /* defaults to top:0, left:0 and so these can be left out */
height: 0; /* hiding text, prevent it peaking out */
width: 100%; /* 686px; fill the parent element */
background-position: left top;
background-repeat: no-repeat;
}
h1#logo {
height: 60px; /* height of replacement image */
}
h1#logo a {
padding-top: 60px; /* height of the replacement image */
background-image: url("logo.png"); /* the replacement image */
}
What method is the best for this sort of thing? Please provide html and css in your answer.
You're missing the option:
<h1>
<a href="http://stackoverflow.com">
<img src="logo.png" alt="Stack Overflow" />
</a>
</h1>
title in href and img to h1 is very, very important!
这篇关于用徽标图像替换 H1 文本:搜索引擎优化和可访问性的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!