簡體   English   中英

如何使用CSS排除懸停效果

[英]How can I exclude a hover effect with CSS

我已經編寫了一些代碼,因此當您在圖像上滾動時會彈出一個desc框,但是設置CSS的方式是我必須在hover類中包括該彈出框,這意味着當您將基本圖像移到保留的方框,我該如何更改,以便將光標從圖標圖像移開后方框消失。

<!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/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM