2013-03-04 124 views
6

我的網站上有一個漂亮的小懸停效果,當用戶懸停在鏈接上時,它可以快速轉換。但是當用戶離開盒子時,影子(和其他特徵)立即消失,而不是退出。有沒有一種方法可以讓屬性淡入和淡出,也許使用某種:un-hover type僞類?謝謝!這裏是CSS塊,如果有幫助:離開懸停的CSS僞類

a.squares:hover, a.squares:active { 
    color: black; 
    background-color: #E8E8E8; 
    box-shadow: 0 0 12px black; 
    -webkit-border-radius: 15px; 
    -moz-border-radius: 15px; 
    border-radius: 15px; 
    -webkit-transition: color 0.1s ease-in-out, background-color 0.1s ease-in-out, box-shadow 0.1s ease-in-out; 
    -moz-transition: color 0.1s ease-in-out, background-color 0.1s ease-in-out, box-shadow 0.1s ease-in-out; 
    transition: color 0.1s ease-in-out, background-color 0.1s ease-in-out, box-shadow 0.1s ease-in-out; 
} 
+0

有不是':un-hover',因爲它作爲僞類沒有意義。見http://stackoverflow.com/questions/11703241/does-css-have-a-blur-selector-pseudo-class/11703334#11703334 – BoltClock 2013-03-04 03:59:24

回答

6

把轉變上a.squaresa.squares:hover

a.squares { 
    -webkit-transition: color 0.1s ease-in-out, background-color 0.1s ease-in-out, box-shadow 0.1s ease-in-out; 
    -moz-transition: color 0.1s ease-in-out, background-color 0.1s ease-in-out, box-shadow 0.1s ease-in-out; 
    transition: color 0.1s ease-in-out, background-color 0.1s ease-in-out, box-shadow 0.1s ease-in-out; 
} 
a.squares:hover, a.squares:active { 
    color: black; 
    background-color: #E8E8E8; 
    box-shadow: 0 0 12px black; 
    -webkit-border-radius: 15px; 
    -moz-border-radius: 15px; 
    border-radius: 15px; 
} 

我通過這個確切的事情去了,當我正要離開約轉變:)

+0

這工作,非常感謝! – grantmcconnaughey 2013-03-04 04:07:07

+0

太棒了!謝謝!但是,如何防止頁面加載時的動畫? – 2015-11-22 19:31:43

+1

@AlexeySidash當屬性更改時發生轉換,以防止頁面加載時的轉換最初禁用轉換('.page-loaded a.squares')或防止屬性發生更改。 – 2015-11-22 23:23:48