html - 如何使用 CSS 排除悬停效果

标签 html css class

我写了一些代码,所以当你滚动图像时会弹出一个 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>

最佳答案

which means when you move off the base image onto the box it stays, how can I change this so the box goes away after moving the cursor from the icon image.

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

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

但请注意,如果它消失时光标再次留在图像上,这可能会导致“闪烁”效果,因为这会触发框再次变得可见……所以只有当框不重叠时这才有效图片。

http://jsfiddle.net/XVgcT/

关于html - 如何使用 CSS 排除悬停效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19329136/

相关文章:

javascript - 为什么我不能从内联 anchor 调用此对象的函数?

html - Powershell:如何引用第n个元素

javascript - 来自HTML图像的jsPDF导致pdf为空

html - 我的表根本没有溢出 div

jquery - accordion-toggles - Jquery 活跃吗?

html - facebook 评论插件 html iframe 内容被剪裁,不会在容器中拉伸(stretch)

html - CSS/HTML : Remove image filter on click

excel - Vba 错误处理和类 (Excel)

c++ - 在类中创建函数的问题

java - 使用类作为变量标识符?