2013-04-14 110 views
0

我一直在考慮this issue在過去的幾天,但我無法弄清楚究竟是什麼問題。爲什麼這個懸停過渡在Chrome中不起作用?

考慮從style.css下面的代碼片段:

.tint:before { 
     -moz-transition: all .3s linear; 
    -webkit-transition: all .3s linear; 
     -ms-transition: all .3s linear; 
      -o-transition: all .3s linear; 
      transition: all .3s linear; 
} 
.tint:hover:before {background:rgba(159,182,205,0.1);} 

正如你可以從上面的代碼中看到,在圖像懸停,應該使用戶要點擊出現「色彩」過渡該圖像。但是,此功能在Chrome中無法使用。

爲什麼懸停轉換在Chrome中不起作用,但在Firefox中工作得很好?

這是預期的行爲?或者Chrome沒有正確渲染這些轉換?

+1

我感覺人最近使用的是Chrome的一些bug的測試版本:d它爲我工作。 :) – Kaloyan

+0

@KaloyanIvanov你有什麼版本的Chrome? – railgun

+0

它說26.0.1410.64米 – Kaloyan

回答

2

這個問題涉及到:在僞類之前。這個類似乎沒有觸發懸停。如果你刪除它,它工作得很好。

.tint { 
-moz-transition: all .3s linear; 
-webkit-transition: all .3s linear; 
-ms-transition: all .3s linear; 
-o-transition: all .3s linear; 
transition: all .3s linear; 
} 
.tint:hover{background:rgba(159,182,205,0.1);} 

這裏是的jsfiddle - http://jsfiddle.net/qGAn9/

UPDATE:

如果:需要僞元素之前,那麼你就可以觸發父元素上懸停。我還必須添加一些其他樣式來使僞元素顯示在最上面。

.tint:before { 
    -moz-transition: all .3s linear; 
    -webkit-transition: all .3s linear; 
    -ms-transition: all .3s linear; 
    -o-transition: all .3s linear; 
    transition: all .3s linear; 

    content: ""; 
    width: 100%; 
    height: 100%; 
    position: absolute; 
} 

.tint:hover:before{background:rgba(159,182,205,0.5);} 

的jsfiddle這裏 - http://jsfiddle.net/qGAn9/2/

+0

':before'被明確聲明,以便色調轉換在圖像上進行。不使用':before'會阻止在圖像頂部顯示過渡。 – railgun

+0

根據您的評論更新了我的答案。 –

+1

爲了使用':hover:before',[IE10 requires](http://css-tricks.com/pseudo-element-animationstransitions-bug-fixed-in-webkit/):':hover' CSS規則也是定義(可以是空的)。 –