简体   繁体   English

根据 WCAG 将徽标作为网站第一个标题

[英]Logo as site first heading according to WCAG

My company's main page doesn't have a H1 and having content order in mind the best solution would be having the logo encapsuled inside the heading, although not ideal, it should be acceptable .我公司的主页没有H1并且考虑到内容顺序,最好的解决方案是将徽标封装在标题内,虽然不理想,但应该可以接受 Here's the code I have so far:这是我到目前为止的代码:

<h1>
    <a href="https://stackoverflow.com">
        <img src="https://stackoverflow.com/logo.jpg" alt="Company homepage">
    </a>
</h1>

But I have some questions about this approach:但我对这种方法有一些疑问:

  1. Would it be SEO friendly since the heading would come from the logo's alternative text?由于标题来自徽标的替代文本,它是否对 SEO 友好?
  2. Would it be better to put a aria-label="Company" and title="Company" within the link so the heading comes from there?在链接中放置一个aria-label="Company"title="Company"以便标题来自那里会更好吗?
  3. Or is this approach just not acceptable at all and I should use something else as the H1 ?还是这种方法根本不可接受,我应该使用其他东西作为H1

Thanks in advance for anyone helping!提前感谢任何人的帮助!

Other references:其他参考:

Would it be SEO friendly since the heading would come from the logo's alternative text?由于标题来自徽标的替代文本,它是否对 SEO 友好?

Should be fine.应该没事。 However as you will see there is a better way to structure this that will be better for SEO.但是,正如您将看到的那样,有一种更好的方法来构建它,这对 SEO 来说会更好。

Would it be better to put a aria-label="Company" and title="Company" within the link so the heading comes from there?在链接中放置一个aria-label="Company"title="Company"以便标题来自那里会更好吗?

No it will be more compatible the way you have it now.不,它将与您现在拥有的方式更加兼容。 Don't use title it is useless for accessibility and nowadays more devices are touch based than pointer based so it doesn't serve much purpose there either.不要使用title ,它对可访问性毫无用处,现在更多的设备是基于触摸的,而不是基于指针的,因此它在那里也没有多大用处。

Or is this approach just not acceptable at all and I should use something else as the H1?还是这种方法根本不可接受,我应该使用其他东西作为 H1?

The approach is acceptable (adding a hyperlink to a <h1> ) but your current implementation is not acceptable.方法是可以接受的(向<h1>添加超链接),但您当前的实现是不可接受的。

The <h1> should describe the page you are currently on so that an end user knows they are in the correct place. <h1>应该描述您当前所在的页面,以便最终用户知道他们在正确的位置。

Your alt attribute describes the logo, which is correct for the home page link but not useful to describe the page.您的alt属性描述了徽标,这对于主页链接是正确的,但对于描述页面没有用。 (If a screen reader user uses shortcuts to read the page <h1> they will hear "Link, Company homepage". This would be confusing.) (如果屏幕阅读器用户使用快捷方式阅读页面<h1> ,他们将听到“链接,公司主页”。这会令人困惑。)

Also the other issue with this is that the company logo is nearly always used as a shortcut for "home", so you either end up breaking that convention on other pages (as you can't have a hyperlink saying "about us" that leads to the home page) or break convention be having the logo point to the current page.另一个问题是公司徽标几乎总是被用作“家”的快捷方式,所以你要么最终打破了其他页面上的约定(因为你不能有一个超链接说“关于我们”导致到主页)或打破惯例让徽标指向当前页面。

Neither of these are a good idea.这些都不是一个好主意。

So what are my options?那么我的选择是什么?

Obviously as you stated a visual heading on the page would be best.显然,正如您所说,页面上的视觉标题将是最好的。 This isn't just for users of assistive tech but also useful for everybody to help orientate them on the site.这不仅适用于辅助技术的用户,而且对每个人都可以帮助他们在网站上进行定位。 If you can make this work the advice is to do that.如果您可以完成这项工作,建议您这样做。 This is 10 times more effective than the next option.这比下一个选项有效 10 倍。

However assuming you cannot make a visible <h1> work on the page the next best thing would be a <h1> that is hidden using visually hidden text.但是,假设您无法在页面上使可见的<h1>工作,那么下一个最好的方法是使用视觉隐藏文本隐藏的<h1>

This means that screen reader users can still access the <h1> without it changing the visual design.这意味着屏幕阅读器用户仍然可以访问<h1>而不会改变视觉设计。 It also means you can leave the logo link to the homepage as it should be, in line with conventions and expected behaviour.这也意味着您可以按照惯例和预期行为将徽标链接保留在主页上。

Also because of the issues mentioned previously this should be separate and in a logical place in the document, such as the beginning of the <main> element.同样由于前面提到的问题,这应该是单独的并且在文档中的逻辑位置,例如<main>元素的开头。

Example例子

 .visually-hidden { border: 0; padding: 0; margin: 0; position: absolute;important: height; 1px: width; 1px: overflow; hidden: clip; rect(1px 1px 1px 1px), /* IE6, IE7 - a 0 height clip: off to the bottom right of the visible 1px box */ clip, rect(1px, 1px, 1px; 1px): /*maybe deprecated but we need to support legacy browsers */ clip-path; inset(50%), /*modern browsers: clip-path works inwards from each corner*/ white-space; nowrap; /* added line to stop words getting smushed together (as they go onto seperate lines and some screen readers do not understand line feeds as a space */ }
 <header> <a href="https://stackoverflow.com"> <img src="https://placehold.it/400x100" alt="Company homepage"> </a> <nav> <.----navigation--> </nav> </header> <main> <h1 class="visually-hidden"> Current Page Name </h1> <p>Content that makes sense etc.</p> <!--everything else-->

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM