如何在触摸设备上管理点击事件和悬停效果?

时间:2017-11-23 16:00:00

标签: css css3 hover touch href

触控设备在第一次点击时同时使用:hoverhref="/products.php"。是否有用于管理菜单导航链接及其子菜单的 CSS 解决方案?



html, body {
  font-family: Arial, Helvetica, sans-serif;
  background-color: tomato;
  height: 100vh;
}

.navigation {
  width: 300px;
}

.mainmenu, .submenu {
  list-style: none;
  padding: 0;
  margin: 0;
}

.mainmenu a {
  display: block;
  background-color: #CCC;
  text-decoration: none;
  padding: 10px;
  color: #000;
}

.mainmenu a:focus, .mainmenu a:hover {
  background-color: #C5C5C5;
}

.mainmenu li:focus .submenu, .mainmenu li:hover .submenu {
  display: block;
  max-height: 200px;
}

.submenu a {
  background-color: #999;
}

.submenu a:focus, .submenu a:hover {
  background-color: #666;
}

.submenu {
  overflow: hidden;
  max-height: 0;
  -webkit-transition: all 0.5s ease-out;
}

<nav class="navigation">
  <ul class="mainmenu">
    <li><a href="">Home</a></li>
    <li><a href="">About</a></li>
    <li><a href="/products.php">Products</a>
      <ul class="submenu">
        <li><a href="/Tops">Tops</a></li>
        <li><a href="/Bottoms">Bottoms</a></li>
        <li><a href="/Footwear">Footwear</a></li>
      </ul>
    </li>
    <li><a href="">Contact us</a></li>
  </ul>
</nav>
&#13;
&#13;
&#13;

演示:https://codepen.io/athimannil/pen/LOrPVw

0 个答案:

没有答案