简体   繁体   中英

how to display drop down menus on tab

Can someone explain how can i make this drop down menu work when the user tabs on the link.

http://jsfiddle.net/NnCVv/234/

<ul id="drop-nav">
  <li><a href="#">Item 1</a></li>
  <li><a href="#">Item 2</a>
    <ul>
      <li><a href="html.html" tabindex="0">HTML</a></li>
      <li><a href="#">CSS</a></li>
      <li><a href="#">JavaScript</a></li>
    </ul>
  </li> 
</ul>



 ul {list-style: none;padding: 0px;margin: 0px;}
  ul li {display: block;position: relative;float: left;border:1px solid #000}
  li ul {display: none;}
  ul li a {display: block;background: #000;padding: 5px 10px 5px 10px;text-decoration: none;
           white-space: nowrap;color: #fff;}
  ul li a:hover {background: #f00;}
  li:hover ul {display: block; position: absolute;}
  li:hover li {float: none;}
  li:hover a {background: #f00;}
  li:hover li a:hover {background: #000;}
  #drop-nav li ul li {border-top: 0px;}
  li:focus ul {display: block; position: absolute;}

if you add tabindex and also add the proper CSS styles to your li elements, it'll work: DEMO

HTML

<ul id="drop-nav">
  <li tabindex="1"><a href="#">Item 1</a></li>
  <li tabindex="2"><a href="#">Item 2</a>
    <ul>
      <li><a href="html.html" tabindex="0">HTML</a></li>
      <li><a href="#">CSS</a></li>
      <li><a href="#">JavaScript</a></li>
    </ul>
  </li> 
</ul>

CSS

  ul {list-style: none;padding: 0px;margin: 0px;}
  ul li {display: block;position: relative;float: left;border:1px solid #000}
  li ul {display: none;}
  ul li a {display: block;background: #000;padding: 5px 10px 5px 10px;text-decoration: none;
           white-space: nowrap;color: #fff;}
  ul li a:hover,ul li:focus a {background: #f00;}
  li:hover ul,li:focus ul {display: block; position: absolute;}
  li:hover li,li:focus li {float: none;}
  li:hover a,li:focus a {background: #f00;}
  li:hover li a:hover,li:focus li a:hover {background: #000;}
  #drop-nav li ul li {border-top: 0px;}

一旦包含以下内容,它将起作用:

<script src="jquery.transit.min.js"></script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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