<?xml version="1.0" encoding="ISO-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="/lib/xsl/devedge-1.00/article_en.xsl"?>
<nde:article 
  xmlns="http://www.w3.org/1999/xhtml"  
  url="/viewsource/2003/reveal-accesskey/"
  xmlns:nde="http://devedge.netscape.com/2002/de"
  xmlns:ent="http://devedge.netscape.com/2003/ent"
  xml:lang="en">

<nde:header>
<nde:title>Revealing Accesskey Information</nde:title>
<nde:category>Article</nde:category>
<nde:pubdate year="2003" month="06" day="20" />
<nde:channels>
<nde:channel id="viewsource" />
<nde:channel id="css" />
</nde:channels>
<nde:keywords>
css, css2, xhtml, accesskey, generated content, accessibility
</nde:keywords>
<nde:summary>
Accesskeys can make a Web page much more usable, but they're usually so thoroughly hidden that nobody knows they're available, let alone what they are.  Contributor Stuart Robinson shows how generated content can be used to make accesskey information visible, and therefore useful as well as usable.
</nde:summary>  
<nde:authlist>
<nde:author>
  <nde:authname>Stuart Robertson</nde:authname>  
  <nde:authaffil>DesignMeme</nde:authaffil>
</nde:author>
</nde:authlist>
  
  </nde:header>

<nde:head>
<style type="text/css"><![CDATA[
@import url(accesskey-popups.css);
]]></style>
</nde:head>

<nde:content>
<ul class="nde-metadata">
<li>© Copyright 2003 Stuart Robertson.  <a href="http://www.designmeme.com/articles/missinglink.shtml">Reprinted</a> with permission.</li>
</ul>

<p>
In his new book "Designing for Web Standards", <a href="http://www.zeldman.com/">Jeffrey 
Zeldman</a> explains how defining the accesskey attribute on link elements 
allows users to navigate websites via the keyboard instead of a mouse. This 
helps users with physical disabilities navigate through a website more easily 
as well as creating a "Hot-Key" like feature that benefits all frequent 
visitors to a site. The accesskey is a useful feature but as Jeffrey notes, 
no widely used browser provides a method for users to display accesskey 
letter assignments, short of viewing the source code. Not knowing what accesskeys 
are associated with each link makes them of limited value, and they are  
under used on most websites.
</p>

<h2>CSS Generated Content</h2>
<p>
The additional features of Cascading Style Sheets, Level 2 (CSS2) that 
modern web browsers are beginning to support provide some possible solutions 
that could encourge the accesskey attribute to be more widely used. Specifically, 
the :before and :after pseudo-elements allow browsers to generate content 
and insert it within a document.
</p>
<p>
The content generated by the pseudo-elements can include quotation marks, 
counters, embeddable objects such as images, and strings of text. Thegenerated 
content is somewhat limited, as the browser will not parse HTML markup included 
in this manner. The text will also appear within the parent element the 
CSS style has been applied to, and can not be independently positioned on 
the page.
</p>
<p>
The good news is that this string of text can include the content from 
one or more of the parent element's attributes. When applied to a link these 
attributes include the url, title, language, link-type, and <i>accesskey</i>. 
Using the :after pseudo-element we can display the otherwise hidden accesskey 
information to the user:
</p>
<pre><![CDATA[
a:after {
   content: " (" attr(accesskey) ") "
   }
]]></pre>
<p>
This will insert the accesskey assignments in parentheses immediately after 
each link on a page without changing the underlying content of the document. 
This increases the usefulness of the accesskey attribute, but displaying 
this information is not relevant to all users and many people would prefer 
that it not appear onscreen at all times. Fortunately we can give users 
some control over when to include this information.
</p>

<h2>Selective Display</h2>
<p>
The first technique we can use to selectively display CSS generated content 
is to use a <a href="http://www.alistapart.com/stories/phpswitch/">style-sheet 
switcher</a>. This gives people the option of choosing a style with enhanced 
accessibility options, including the display of the accesskey attribute 
with each link. If the user doesn't want to be presented with this information, 
they can select a style-sheet that doesn't include this feature. The ability 
to use the accesskey feature will be available all users, regardless of 
the style-sheet they are using to view the website.
</p>
<p>
The second method, is to make use of a contextual selector to specify that 
the generated content is only applied to the document when the user requires 
it. By using :hover and :focus pseudo classes, and combining them with the 
:before and :after pseudo-elements, the accesskey assignments can be displayed 
onscreen when the user tabs onto a link or rolls over a link with their 
cursor. The CSS properties for these two contextual selectors can be defined 
at the same time by using a comma to group them together:
</p>
<pre><![CDATA[
a:hover:after, a:focus:after { }
]]></pre>
<p>
Depending on the pseudo-element used, the generated text will be inserted 
on the page either before or after the contents of the link. It's important 
to note that adding extra text wil change the width of the link, so careful 
use of CSS to control formatting and positioning may be necessary to avoid 
unintended visual disruptions, such as "jumping text" during a rollover.
</p>


<h2>Accesskey Pop-up Menu</h2>
<p>
This menu was created with an ordinary bulleted list and the CSS2 :after pseudo-element.
Move your cursor over the links to see additional pop-up information
including the target url, title, type of link and accesskey. These links have had their tabindex attributes set, allowing you to use the Tab key to move between them and display the pop-up information.</p>

<h3>Example</h3>

<div id="container">
<div id="menu">
<ul>
<li>
<a href="http://www.designmeme.com/" title="Design Meme" rel="Index" accesskey="a" tabindex="1">Home</a>
</li>
<li>
<a href="http://www.designmeme.com/articles/missinglink.shtml" title="The Search for the Missing Link" rel="Article" accesskey="b" tabindex="2">Article
1</a>
</li>
<li>
<a href="http://www.designmeme.com/articles/cssrollovers.shtml" title="CSS Image Rollovers" rel="Article" accesskey="c" tabindex="3">Article
2</a>
</li>
<li>
<a href="http://www.w3.org/Style/CSS/" title="CSS Reference" rel="Help" accesskey="d" tabindex="4">Help</a>
</li>
</ul>
</div>
</div>

<p>
This example should work in <a href="http://www.mozilla.org/">Mozilla</a>, <a href="http://www.netscape.com">Netscape 6+</a>, <a href="http://www.opera.com">Opera 7</a>, <a href="http://www.apple.com/safari">Safari</a>, and <a href="http://www.konqueror.org/">Konqueror</a>. Browsers without CSS should be presented with regular unstyled content, in this
case a simple bulleted list of links. Older web browsers, including all current versions of Internet Explorer lack support for the :before and :after
pseudo-elements. When these browsers hover or tab over the links in the menu, they will not be presented with the generated content. 
These browsers may still display the contents of the Title attribute in a small pop-up box, and they can use both the links and accesskeys
normally, although as we previously noted they would have no way of knowing what they had been set to.
</p>

<h2>Sample Code</h2>
<p>
This is an example of the CSS code used to create a  basic menu that selectively
reveals accesskey information when the user rolls or tabs over
a link. This example makes further use of CSS contextual selectors to
specify these styles only be applied to a bulleted list of links contained
within &lt;div id=&quot;menu&quot;&gt;. You will likely need to spend
some time adjusting the formatting and positioning of this menu before using it on a website, but this will get you started:
</p>
<pre><![CDATA[
#menu {
position: absolute;
top: 330px;
}

#menu li {
list-style-type: none;
float: left;
}

#menu a {
text-decoration: none;
width: 100px;
display: block;
padding: 2px;
}

#menu a:hover:after, #menu a:focus:after {
content: attr(title) " (" attr(rel) ") \A" attr(href) "\A Access Key: " attr(accesskey);
display: block;
text-decoration: none;
color: #666;
background-color: #FC6;
border: 1px solid #666;
padding: 2px;
white-space: pre;
}
]]></pre>
</nde:content>

<nde:related area="nde">
 <nde:item url="/central/css/">CSS Central</nde:item>
</nde:related>

<nde:related area="ext">
 <nde:item url="http://www.designmeme.com/">DesignMeme</nde:item>
</nde:related>

</nde:article>
