0
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-01-28 20:52:21 +01:00

Merge pull request #15714 from patrickhlauke/skip-link-fixes

Skip link workarounds for Chrome and IE
This commit is contained in:
Patrick H. Lauke 2015-02-04 15:38:17 +00:00
commit 27677fab5b
4 changed files with 14 additions and 4 deletions

View File

@ -3,12 +3,17 @@
<p class="lead">Bootstrap follows common web standards and&mdash;with minimal extra effort&mdash;can be used to create sites that are accessible to those using <abbr title="Assistive Technology" class="initialism">AT</abbr>.</p>
<h3>Skip navigation</h3>
<p>If your navigation contains many links and comes before the main content in the DOM, add a <code>Skip to main content</code> link before the navigation <a href="http://a11yproject.com/posts/skip-nav-links/">(read why)</a>. Using the <code>.sr-only</code> class will visually hide the skip link, and the <code>.sr-only-focusable</code> class will ensure that the link becomes visible once focused (for sighted keyboard users).</p>
<p>If your navigation contains many links and comes before the main content in the DOM, add a <code>Skip to main content</code> link before the navigation (for a simple explanation, see this <a href="http://a11yproject.com/posts/skip-nav-links/">A11Y Project article on skip navigation links</a>). Using the <code>.sr-only</code> class will visually hide the skip link, and the <code>.sr-only-focusable</code> class will ensure that the link becomes visible once focused (for sighted keyboard users).</p>
<div class="bs-callout bs-callout-danger" id="callout-tables-striped-ie8">
<p>Due to long-standing shortcomings/bugs in Chrome (see <a href="https://code.google.com/p/hromium/issues/detail?id=262171" title="Chromium bug tracker - Issue 262171: Focus should cycle from named anchor">issue 262171 in the Chromium bug tracker</a>) and Internet Explorer (see this article on <a href="http://accessibleculture.org/articles/2010/05/in-page-links/">in-page links and focus order</a>), you will need to make sure that the target of your skip link is at least programmatically focusable by adding <code>tabindex="-1"</code>.</p>
<p>In addition, you may want to explicitly suppress a visible focus indication on the target (particularly as Chrome currently also sets focus on elements with <code>tabindex="-1"</code> when they are clicked with the mouse) with <code>#content:focus { outline: none; }</code>.</p>
<p>Note that this bug will also affect any other in-page links your site may be using, rendering them useless for keyboard users. You may consider adding a similar stop-gap fix to all other named anchors / fragment identifiers that act as link targets.</p>
</div>
{% highlight html %}
<body>
<a href="#content" class="sr-only sr-only-focusable">Skip to main content</a>
...
<div class="container" id="content">
<div class="container" id="content" tabindex="-1">
<!-- The main page content -->
</div>
</body>

View File

@ -11,7 +11,7 @@
{% include nav/main.html %}
<!-- Docs page layout -->
<div class="bs-docs-header" id="content">
<div class="bs-docs-header" id="content" tabindex="-1">
<div class="container">
<h1>{{ page.title }}</h1>
<p>{{ page.lead }}</p>

View File

@ -93,6 +93,7 @@ body {
* Fancy skip link
*
* Make it look a bit less "bare bones"
* Also includes focus suppression for the Chrome tabindex="-1" workaround
*/
#skippy {
@ -108,6 +109,10 @@ body {
outline: 1px dotted;
}
#content:focus {
outline: none;
}
/*
* Main navigation

View File

@ -4,7 +4,7 @@ title: Bootstrap &middot; The world's most popular mobile-first and responsive f
---
<main class="bs-docs-masthead" id="content" role="main">
<main class="bs-docs-masthead" id="content" role="main" tabindex="-1">
<div class="container">
<span class="bs-docs-booticon bs-docs-booticon-lg bs-docs-booticon-outline">B</span>
<p class="lead">Bootstrap is the most popular HTML, CSS, and JS framework for developing responsive, mobile first projects on the web.</p>