Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try this out: <a href="http://jsfiddle.net/peterjmag/EnVCf/6/" rel="nofollow">http://jsfiddle.net/peterjmag/EnVCf/6/</a></p> <p>In order to get this to work, the parent list item needs to be focusable. One way to do that is just to make it a link like I did for this example, but if you don't want it to be a link, you can also <a href="http://snook.ca/archives/accessibility_and_usability/elements_focusable_with_tabindex" rel="nofollow">make it focusable by adding a tabindex attribute</a>. (Here's an example using tabindex: <a href="http://jsfiddle.net/peterjmag/EnVCf/8/" rel="nofollow">http://jsfiddle.net/peterjmag/EnVCf/8/</a>.)</p> <h3>HTML</h3> <pre><code>&lt;input&gt;Click here first then try and tab down through below menu items without clicking on the purple box with your cursor. How can I achieve this with CSS?&lt;/input&gt; &lt;ul class="nav"&gt; &lt;li&gt; &lt;a href="#"&gt;Select&lt;/a&gt; &lt;ul class="dropdown"&gt; &lt;li&gt;&lt;a href="#"&gt;Item 1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Item 2&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Item 3&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <h3>CSS</h3> <pre><code>.nav { margin: 10px; padding: 10px; border: 2px solid purple; width: 200px; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; } .nav &gt; li &gt; .dropdown { display: none; } .nav &gt; li:hover &gt; .dropdown, .nav &gt; li.hover &gt; .dropdown { display: block; background: #f9f9f9; border-top: 1px solid purple; } .dropdown &gt; li { padding: 5px; border-bottom: 1px solid #4f4f4f; } .dropdown &gt; li:hover, .dropdown &gt; li.hover { background: white; } .dropdown &gt; li:hover &gt; a, .dropdown &gt; li.hover &gt; a { color: red; } </code></pre> <p>(Note the additional <code>li.hover</code> selectors here, which you need in order to fake the hover state on keyboard focus.)</p> <h3>jQuery</h3> <pre><code>$.fn.accessibleDropDown = function () { var el = $(this); /* Make dropdown menus keyboard accessible */ $("a", el).on("focus", function() { $(this).parents("li").addClass("hover"); }).blur(function() { $(this).parents("li").removeClass("hover"); }); } $(".nav").accessibleDropDown(); </code></pre> <p>I used jQuery 1.9 for this example (and updated the event handler to match), but it should work as is back to 1.7. I adapted it from this blog post: <a href="http://uablogs.missouri.edu/interface/2011/08/keyboard-accessible/" rel="nofollow">http://uablogs.missouri.edu/interface/2011/08/keyboard-accessible/</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload