下拉菜单 - 子菜单菜单在悬停时消失

时间:2016-10-01 22:09:06

标签: html css css3

除了子菜单外,一切都很好,而在悬停时它会在悬停时消失。我确信悬停时会出现一些问题。即

.dropdown-content a:hover + .dropdown-submenu {
   display: block;
}



.icon-cadet-left {
  float: right;
}
.dropbtn {
  overflow: hidden;
  width: 300px;
  background-color: #338d99;
  color: white;
  padding: 16px;
  font-family: 'Play';
  font-size: 20px;
  border: none;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 2px;
}
.dropdown {
  position: relative;
  display: block;

}
.dropdown-content {
  display: none;
    position: absolute;
  background-color: #e0e0e0;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  margin:0px; 
}
.dropdown-content a {
  width: 300px;
  color: black;
  font-family: 'Play';
  letter-spacing: 2px;
  padding: 12px 16px;
  text-decoration: none !important;
  display: block;
  text-align: center;
  border-bottom: 0.1em solid #333;
  border-radius: 5%;
  text-transform: uppercase;
  
}
.dropdown-submenu {
  display: none;
  margin:0px;
  background-color: #e0e0e0;
  position: absolute;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  left: 100%;
  top: 0px;
 }

.dropdown-submenu a {
  width: 300px;
  color: black;
  font-family: 'Play';
  letter-spacing: 2px;
  padding: 12px 16px;
  text-decoration: none !important;
  display: block;
  text-align: center;
  border-bottom: 0.1em solid #333;
  border-radius: 5%;
  text-transform: uppercase;

}

.dropdown-content a:hover {
  background-color: #f1f1f1;
  color:#909090;
}
.dropdown-submenu a:hover {
  background-color: #f1f1f1
}
.dropdown:hover .dropdown-content {
  display: block;
}
 .dropdown-content a:hover + .dropdown-submenu {
  display: block;
}
.dropdown:hover .dropbtn {
  background-color: #29727c;
}

<div class="pricing-button">
          <div class="dropdown">
            <button class="dropbtn">Logo Design</button>
                <div class="dropdown-content animated bounce">
                  <a href="#">Logo & Identity<i class="fa fa-caret-right icon-cadet-left"></i></a>
                      <div class="dropdown-submenu">
                        <a href="#">Logo Design</a>
                        <a href="#">Business Cards</a>
                        <a href="#">Sationary</a>
                        <a href="#">Holiday Doodles</a>
                      </div>
                  <a href="#">Business & Advertising<i class="fa fa-caret-right icon-cadet-left"></i></a>
                      <div class="dropdown-submenu">
                        <a>Sample 01</a>
                        <a>Sample 02</a>
                        <a>Sample 03</a>
                        <a>Sample 04</a>
                      </div>
                  <a href="#">Website & Digitals<i class="fa fa-caret-right icon-cadet-left"></i></a>
                      <div class="dropdown-submenu">
                        <a>Option 01</a>
                        <a>Option 02</a>
                        <a>Option 03</a>
                        <a>Option 04</a>
                      </div>
                  <a href="#">Textile Designing<i class="fa fa-caret-right icon-cadet-left"></i></a>
                      <div class="dropdown-submenu">
                        <a>Sample 01</a>
                        <a>Sample 02</a>
                        <a>Sample 03</a>
                        <a>Sample 04</a>
                      </div>
                </div>
          </div>
        </div>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:2)

你应该使用

.dropdown-submenu

而不是

a

原因是,一旦您移动鼠标悬停.dropdown-submenu blocked节点不再悬停,因此.icon-cadet-left { float: right; } .dropbtn { overflow: hidden; width: 300px; background-color: #338d99; color: white; padding: 16px; font-family: 'Play'; font-size: 20px; border: none; cursor: pointer; text-transform: uppercase; letter-spacing: 2px; } .dropdown { position: relative; display: block; } .dropdown-content { display: none; position: absolute; background-color: #e0e0e0; box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2); margin:0px; } .dropdown-content a { width: 300px; color: black; font-family: 'Play'; letter-spacing: 2px; padding: 12px 16px; text-decoration: none !important; display: block; text-align: center; border-bottom: 0.1em solid #333; border-radius: 5%; text-transform: uppercase; } .dropdown-submenu { display: none; margin:0px; background-color: #e0e0e0; position: absolute; box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2); left: 100%; top: 0px; } .dropdown-submenu a { width: 300px; color: black; font-family: 'Play'; letter-spacing: 2px; padding: 12px 16px; text-decoration: none !important; display: block; text-align: center; border-bottom: 0.1em solid #333; border-radius: 5%; text-transform: uppercase; } .dropdown-content a:hover { background-color: #f1f1f1; color:#909090; } .dropdown-submenu a:hover { background-color: #f1f1f1 } .dropdown:hover .dropdown-content { display: block; } .dropdown-content:hover .dropdown-submenu { display: block; } .dropdown:hover .dropbtn { background-color: #29727c; }不是<div class="pricing-button"> <div class="dropdown"> <button class="dropbtn">Logo Design</button> <div class="dropdown-content animated bounce"> <a href="#">Logo & Identity<i class="fa fa-caret-right icon-cadet-left"></i></a> <div class="dropdown-submenu"> <a href="#">Logo Design</a> <a href="#">Business Cards</a> <a href="#">Sationary</a> <a href="#">Holiday Doodles</a> </div> <a href="#">Business & Advertising<i class="fa fa-caret-right icon-cadet-left"></i></a> <div class="dropdown-submenu"> <a>Sample 01</a> <a>Sample 02</a> <a>Sample 03</a> <a>Sample 04</a> </div> <a href="#">Website & Digitals<i class="fa fa-caret-right icon-cadet-left"></i></a> <div class="dropdown-submenu"> <a>Option 01</a> <a>Option 02</a> <a>Option 03</a> <a>Option 04</a> </div> <a href="#">Textile Designing<i class="fa fa-caret-right icon-cadet-left"></i></a> <div class="dropdown-submenu"> <a>Sample 01</a> <a>Sample 02</a> <a>Sample 03</a> <a>Sample 04</a> </div> </div> </div> </div>

这是一个工作版本:

[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
#import <StoreKit/StoreKit.h>

答案 1 :(得分:1)

您忘了将.dropdown-submenu:hover添加到display: block;规则中。如果没有,则子菜单会消失,因为您不再悬停在a标记上。

.icon-cadet-left {
  float: right;
}
.dropbtn {
  overflow: hidden;
  width: 300px;
  background-color: #338d99;
  color: white;
  padding: 16px;
  font-family: 'Play';
  font-size: 20px;
  border: none;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 2px;
}
.dropdown {
  position: relative;
  display: block;
}
.dropdown-content {
  display: none;
  position: absolute;
  background-color: #e0e0e0;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  margin: 0px;
}
.dropdown-content a {
  width: 300px;
  color: black;
  font-family: 'Play';
  letter-spacing: 2px;
  padding: 12px 16px;
  text-decoration: none !important;
  display: block;
  text-align: center;
  border-bottom: 0.1em solid #333;
  border-radius: 5%;
  text-transform: uppercase;
}
.dropdown-submenu {
  display: none;
  margin: 0px;
  background-color: #e0e0e0;
  position: absolute;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  left: 100%;
  top: 0px;
}
.dropdown-submenu a {
  width: 300px;
  color: black;
  font-family: 'Play';
  letter-spacing: 2px;
  padding: 12px 16px;
  text-decoration: none !important;
  display: block;
  text-align: center;
  border-bottom: 0.1em solid #333;
  border-radius: 5%;
  text-transform: uppercase;
}
.dropdown-content a:hover {
  background-color: #f1f1f1;
  color: #909090;
}
.dropdown-submenu a:hover {
  background-color: #f1f1f1
}
.dropdown:hover .dropdown-content {
  display: block;
}
.dropdown-content a:hover + .dropdown-submenu,
.dropdown-submenu:hover {
  display: block;
}
.dropdown:hover .dropbtn {
  background-color: #29727c;
}
<div class="pricing-button">
  <div class="dropdown">
    <button class="dropbtn">Logo Design</button>
    <div class="dropdown-content animated bounce">
      <a href="#">Logo & Identity<i class="fa fa-caret-right icon-cadet-left"></i></a>
      <div class="dropdown-submenu">
        <a href="#">Logo Design</a>
        <a href="#">Business Cards</a>
        <a href="#">Sationary</a>
        <a href="#">Holiday Doodles</a>
      </div>
      <a href="#">Business & Advertising<i class="fa fa-caret-right icon-cadet-left"></i></a>
      <div class="dropdown-submenu">
        <a>Sample 01</a>
        <a>Sample 02</a>
        <a>Sample 03</a>
        <a>Sample 04</a>
      </div>
      <a href="#">Website & Digitals<i class="fa fa-caret-right icon-cadet-left"></i></a>
      <div class="dropdown-submenu">
        <a>Option 01</a>
        <a>Option 02</a>
        <a>Option 03</a>
        <a>Option 04</a>
      </div>
      <a href="#">Textile Designing<i class="fa fa-caret-right icon-cadet-left"></i></a>
      <div class="dropdown-submenu">
        <a>Sample 01</a>
        <a>Sample 02</a>
        <a>Sample 03</a>
        <a>Sample 04</a>
      </div>
    </div>
  </div>
</div>