将H1文本替换为徽标图片:SEO和辅助功能的最佳方法? [英] Replacing H1 text with a logo image: best method for SEO and accessibility?

查看:322
本文介绍了将H1文本替换为徽标图片:SEO和辅助功能的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎有一些不同的技术,所以我希望得到一个确定的答案这个...



在网站上,通常的做法是创建一个链接到首页的徽标。我想做同样的,同时最好地优化搜索引擎,屏幕阅读器,IE 6+和禁用CSS和/或图像的浏览器。



示例一:不使用h1标记。对于SEO不好,对吗?

 < div id =logo> 
< a href =>
< img src =logo.pngalt =Stack Overflow/>
< / a>
< / div>

示例二:找到这里。 CSS似乎有点怪。

 < 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;示例三:相同的HTML,不同的方法使用文本缩进。这是图片替换的Phark方法。

 < 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; / *大于实际图像? * /
height:120px;
text-decoration:none;
border:0;
}

示例四: Leahy-Langridge-Jefferies方法

 < h1 id =logoclass =logo> 
< a href => Stack Overflow< / a>
< / h1>



  / * css * 
h1.logo {
margin-top:15px; / *为这个特定的网站,设置为你喜欢* /
position:relative; / *允许子元素放置在wrt这一个* /
overflow:hidden; / *不要让内容泄漏超出头 - 不需要作为锚的高度将覆盖整个头* /
padding:0; / *需要计算复位/默认样式* /
}

h1.logo a {
position:absolute; / *默认为top:0,left:0,所以可以省略* /
height:0; / *隐藏文本,防止它突出* /
width:100%; / * 686px;填充父元素* /
background-position:left top;
background-repeat:no-repeat;
}

h1#logo {
height:60px; / *替换图像的高度* /
}

h1#logo a {
padding-top:60px; / *替换图像的高度* /
background-image:url(logo.png); / *替换镜像* /
}

事情?请在您的答案中提供html和css。

解决方案

您缺少该选项:

 < h1> 
< a href =http://stackoverflow.com>
< img src =logo.pngalt =Stack Overflow/>
< / a>
< / h1>


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>

这篇关于将H1文本替换为徽标图片:SEO和辅助功能的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆