How do I fix this error in HTML + CSS Sub-Menus?

0

The submenus of my menu appear without having to move the mouse in the Menu, when going over the 'ul' of the submenu they already appear, I ended up getting lost in my code and now I do not think where I made that mistake, this error of appearing the submenu without hovering the mouse in the menu ??

* {
  margin: 0;
  padding: 0;
}

.menu {
  height: 50px;
  background-color: #1a1a1a;
  font-family: Roboto;
  box-shadow: 0px 0px 100px 5px;
  display: flex;
  width: 100%;
}

.menu h1 {
  font-size: 18px;
  text-align: left;
  padding: 12.5px 0 12.5px 12.5px;
  color: white;
  width: 0;
}

.menu ul {
  margin: 0 auto;
}

.menu ul li ul {
  width: 100%;
}

.menu ul li {
  display: inline-block;
  width: 150px;
  padding: 0px 10px;
  line-height: 25px;
  padding: 0;
  position: relative;
}

.menu ul li a {
  text-align: center;
  font-size: 18px;
}

.menu a {
  padding: 12.5px;
  display: block;
  text-decoration: none;
  color: #666666;
}

.menu ul ul {
  background-color: black;
  position: absolute;
  opacity: 0;
  transition: all 500ms;
}

.menu ul ul li {
  float: none;
  border-bottom: solid 1px #262626;
}

.menu ul li:hover ul {
  opacity: 1;
}

.menu ul ul a:hover {
  transition: all 0.4s ease;
  background-color: #262626;
  color: white;
}

.menu a:hover {
  transition: all 0.4s ease;
  color: white;
}

.menu ul ul li {
  background-color: #1a1a1a;
}

.menu ul ul a {
  font-size: 17px;
}

.menu ul ul li a:hover ul ul ul {
  visibility: visible;
}
<body>
  <nav class="menu">
    <h1>Logomarca</h1>
    <ul>
      <li><a href="#">Home</a></li>
      <li><a href="#">Home2</a>
        <ul>
          <li><a href="#">SubA</a></li>
          <li><a href="#">SubB</a></li>
        </ul>
      </li>
      <li><a href="#">Home3</a>
        <ul>
          <li><a href="#">SubC</a></li>
          <li><a href="#">SubD</a></li>
        </ul>
      </li>
    </ul>
  </nav>
</body>
    
asked by anonymous 23.09.2018 / 07:38

1 answer

2

Another option is to use visibility: visible and visibility: hidden , it together with opacity , will hide the submenu and leave it with the transition:

* {
  margin: 0;
  padding: 0;
}

.menu {
  height: 50px;
  background-color: #1a1a1a;
  font-family: Roboto;
  box-shadow: 0px 0px 100px 5px;
  display: flex;
  width: 100%;
}

.menu h1 {
  font-size: 18px;
  text-align: left;
  padding: 12.5px 0 12.5px 12.5px;
  color: white;
  width: 0;
}

.menu ul {
  margin: 0 auto;
}

.menu ul li ul {
  width: 100%;
}

.menu ul li {
  display: inline-block;
  width: 150px;
  padding: 0px 10px;
  line-height: 25px;
  padding: 0;
  position: relative;
}

.menu ul li a {
  text-align: center;
  font-size: 18px;
}

.menu a {
  padding: 12.5px;
  display: block;
  text-decoration: none;
  color: #666666;
}

.menu ul ul {
  background-color: black;
  position: absolute;
  visibility: hidden;
  opacity: 0;
  transition: all 500ms;
}

.menu ul ul li {
  float: none;
  border-bottom: solid 1px #262626;
}

.menu ul li:hover ul {
  visibility: visible;
  opacity: 1;
}

.menu ul ul a:hover {
  transition: all 0.4s ease;
  background-color: #262626;
  color: white;
}

.menu a:hover {
  transition: all 0.4s ease;
  color: white;
}

.menu ul ul li {
  background-color: #1a1a1a;
}

.menu ul ul a {
  font-size: 17px;
}

.menu ul ul li a:hover ul ul ul {
  visibility: visible;
}
<body>
  <nav class="menu">
    <h1>Logomarca</h1>
    <ul>
      <li><a href="#">Home</a></li>
      <li><a href="#">Home2</a>
        <ul>
          <li><a href="#">SubA</a></li>
          <li><a href="#">SubB</a></li>
        </ul>
      </li>
      <li><a href="#">Home3</a>
        <ul>
          <li><a href="#">SubC</a></li>
          <li><a href="#">SubD</a></li>
        </ul>
      </li>
    </ul>
  </nav>
</body>
    
23.09.2018 / 08:35