CSS悬停在Keep菜单显示块上

时间:2019-03-13 15:55:09

标签: html css

我使用html和css创建了一个通知系统(请参阅下文),但是当我将鼠标悬停在图标上时,菜单会显示正确,但是当我选择任何一个图标时,菜单就会消失。尽管从技术上讲,我并没有将鼠标悬停在上面,因为有一个很小的差距,有什么办法可以解决这个小延迟吗?

.numberCircle {
    width: 30px;
    line-height: 30px;
    border-radius: 50%;
    text-align: center;
    font-size: 20px;
    position:absolute;
    margin-left:30px;
    margin-bottom:10px;
    background-color:red;
    color:white;
}

       .showme {
  display: none;
  position: absolute;
  width: 153px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 1;
  background-color:#1D1E22;
  border: 3px solid white;
  text-align:center !important;

}
 .Resources:hover .showme {display: block;}

.Resources:hover ~ .showme {
display:block;

}
.showme:hover{
    display:block;

}

.Resources:hover .showme {
  display: block;
}

.showme {
  top: 40px;
  position: relative;
  background: #ffffff;
  border: 1px solid #719ECE;  /*set border colour here*/
  width: 400px;
  height: 200px;
  border-radius: 3px;
  -webkit-filter: drop-shadow(0 1px 10px rgba(113, 158, 206, 0.8)); /*set shadow colour  and size here*/
  -moz-box-shadow: 0 1px 10px rgba(113, 158, 206, 0.8);
  filter: drop-shadow(0 1px 10px rgba(113, 158, 206, 0.8));
}

.showme:after,
.showme:before {
  bottom: 100%;
  border: solid transparent;
  content: " ";
  height: 0;
  width: 0;
  position: absolute;
  pointer-events: none;
}

.showme:after {
  border-color: rgba(255, 255, 255, 0);
  border-bottom-color: #ffffff;
  border-width: 19px;
  left: 50%;
  margin-left: -19px;
}

.showme:before {
  border-color: rgba(113, 158, 206, 0);
  border-bottom-color: #719ECE;
  border-width: 20px;
  left: 50%;
  margin-left: -20px;
}
<div class="Resources" style=" width: 60px; height: 70px; float:left;margin-top:30px">
    <div class="numberCircle">1</div>
    <div id="ctl00_TopMenu_FontAwesome_divFA">
    
<i class="fa fa-fw  fa-bell fa-3x " aria-hidden="true" style="   color:black;padding-top:10px;"  ></i>

</div>



<link rel='stylesheet' href='https://use.fontawesome.com/releases/v5.7.0/css/all.css' integrity='sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ' crossorigin='anonymous'>
    
</div>

<div class="showme" style="position:absolute;margin-left:-190px;margin-top:80px;text-align:center;padding:20px;">  
            <a href="../../Brands.aspx" id="ctl00_TopMenu_A1" style="width:150px">Brands</a>
            <hr />
            <a href="../../StockImages.aspx" id="ctl00_TopMenu_A2" style="width:150px">Stock Images</a>
            <hr />
            <a href="../../HowTo.aspx" id="ctl00_TopMenu_A3" style="width:150px">How-To's</a>
            <hr />
        </div>

2 个答案:

答案 0 :(得分:0)

在HTML代码中,将行高添加到“资源”样式中,即

<div class="Resources" style=" width: 60px; height: 70px; float:left;margin-top:30px; line-height: 70px;">

JS Fiddle

答案 1 :(得分:0)

您需要重叠,才能使:hover继续工作。我建议用.showme包装div,其目的是完成重叠,而.showme保留用于视觉目的。

.showme-wrap {
  display: none;
  position: absolute;
  margin-left:-190px;
  text-align:center;
  z-index: 1;
}

.numberCircle {
  width: 30px;
  line-height: 30px;
  border-radius: 50%;
  text-align: center;
  font-size: 20px;
  position:absolute;
  margin-left:30px;
  margin-bottom:10px;
  background-color:red;
  color:white;
}

.showme {
  width: 153px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  background-color:#1D1E22;
  border: 3px solid white;
  padding:20px;
  text-align:center !important;
}

.Resources:hover .showme-wrap {
  display:block;
}

.showme-wrap {
  display: none;
  position: absolute;
  margin-left:-190px;
  text-align:center;
  z-index: 1;
}

.showme:hover{
  display:block;
}

.Resources:hover .showme {
  display: block;
}

.showme {
  top: 40px;
  position: relative;
  background: #ffffff;
  border: 1px solid #719ECE;  /*set border colour here*/
  width: 400px;
  height: 200px;
  border-radius: 3px;
  -webkit-filter: drop-shadow(0 1px 10px rgba(113, 158, 206, 0.8)); /*set shadow colour  and size here*/
  -moz-box-shadow: 0 1px 10px rgba(113, 158, 206, 0.8);
  filter: drop-shadow(0 1px 10px rgba(113, 158, 206, 0.8));
}

.showme:after,
.showme:before {
  bottom: 100%;
  border: solid transparent;
  content: " ";
  height: 0;
  width: 0;
  position: absolute;
  pointer-events: none;
}

.showme:after {
  border-color: rgba(255, 255, 255, 0);
  border-bottom-color: #ffffff;
  border-width: 19px;
  left: 50%;
  margin-left: -19px;
}

.showme:before {
  border-color: rgba(113, 158, 206, 0);
  border-bottom-color: #719ECE;
  border-width: 20px;
  left: 50%;
  margin-left: -20px;
}
<link rel='stylesheet' href='https://use.fontawesome.com/releases/v5.7.0/css/all.css' integrity='sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ' crossorigin='anonymous'>

<div class="Resources" style="width: 60px; height: 70px; float:left;margin-top:30px">
  <div class="numberCircle">1</div>
  <div id="ctl00_TopMenu_FontAwesome_divFA">
    <i class="fa fa-fw  fa-bell fa-3x " aria-hidden="true" style="color:black;padding-top:10px;"></i>
  </div>
  
  <div class="showme-wrap">
    <div class="showme" style="">  
        <a href="../../Brands.aspx" id="ctl00_TopMenu_A1" style="width:150px">Brands</a>
        <hr />
        <a href="../../StockImages.aspx" id="ctl00_TopMenu_A2" style="width:150px">Stock Images</a>
        <hr />
        <a href="../../HowTo.aspx" id="ctl00_TopMenu_A3" style="width:150px">How-To's</a>
        <hr />
    </div>
  </div>
</div>