如何使用 CSS 排除悬停效果



我已经编写了一些代码,因此当您滚动图像时会弹出一个 desc 框,但是它的 CSS 设置方式我必须在悬停类中包含弹出框,这意味着当您从基本图像移动到它停留的框中时,我该如何更改它,以便在将光标从图标图像上移动后框消失。

<!DOCTYPE html>
<html>
<head>
<style> 
p { margin-top: -6px; }
h1.d1 {
    color: #0195d3;
    font-size: 18px;
    font-weight:bold;
    font-family:"Veranda",Arial;
    letter-spacing:.8px;
    text-align:left;
    }
p.d2 {
    color:#c8c8c8;
    font-size: 12px;
    font-family:"Veranda",Arial;
    letter-spacing:.05px;
    line-height:100%;
    text-align:left;
    }
.desc{
    background: black;
    opacity: .85;
    height: 140px;
    width: 180px;
    margin: 0 auto;
    position: absolute;
    text-align: center;
    top: -100px;
    left:-20px;
    display:none;
    padding:1px 20px;
}
.desc:after{
    content:'';
    position:absolute;
    bottom:-5px;
    width:20px;
    height:20px;
    background:black;
    left:20%;
    margin-left:-10px;
    -moz-transform:rotate(45deg);
    -webkit-transform:rotate(45deg);
    transform:rotate(45deg);
}
.icon {
    margin:200px;
    float:left;
    position:relative;
    cursor:pointer;
}
.icon:hover .desc{
    display:block;
}
</style>
</head>
<body>
<div class="icon">
<img src="Images/Icon/Vault.png">
<div class="desc">
<h1 class="d1">Vault</h1>
<p class="d2">9/24/13</p>
<p class="d2">Who knew a 2D platformer could also be an epic RPG quest?  
Vault is about exploration and...</p>
</div>
</div>
</body>
</html>

这意味着当您从基本图像移动到它保留的盒子上时,我该如何更改它,以便在将光标从图标图像上移动后盒子消失。

通过简单地告诉它在自己悬停时再次消失:

.icon .desc:hover { display:none; }

但请注意,如果它消失,这可能会导致"闪烁"效果,再次将光标留在图像上,因为这将触发框再次变得可见......因此,只有当框不与图像重叠时,这才真正有效。

http://jsfiddle.net/XVgcT/

最新更新