[HTML5] Focus management using CSS, HTML, and JavaScript

來源:互聯網
上載者:User

標籤:absolute   cli   rem   link   which   context   man   something   opp   

Something important to consider when coding a web application is managing the user‘s focus. For keyboard and screen reader users, we must ensure their focus is not dropped as content is deleted or shown in new contexts. Skip links also provide a way for users to get past a lot of content. In this lesson, you‘ll learn HTML, CSS and JavaScript techniques for focus management that can be applied to many situations.

 

For example, you have a list of items, when you want to delete an item, you and want auto foucs on next item‘s delete button.

All what you need to do is to find next item, and send focus onto it.

    $(‘.btn-delete‘).on(‘click‘, function() {        $(this).parent().remove();        listItems.find(‘.btn-delete‘).first().focus();    });

 

Next thing if you want the items which are out of foucs managmenet not to have the outline when you nav around the page.

[tabindex="-1"] {    outline: 0;}

 

To build a skip links: It hidden by default, but when we use Tab keyboard, it will shows up.

  <ul class="skip-links">    <li><a href="#main">Main content</a></li>    <li><a href="#footer">Global footer</a></li>  </ul>
ul.skip-links {    list-style: none;    position: absolute;}    ul.skip-links a {        background-color: #fff;        display: block;        left: -999999px;        padding: 1em;        position: absolute;    }    ul.skip-links a:focus {        left: 0;    }

 

[HTML5] Focus management using CSS, HTML, and JavaScript

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.