2014-11-08 111 views
1

我知道這個問題可能已被回答了幾次。但我需要一個適用於任何圖像的解決方案。如何在懸停的圖像上顯示圖像

我有一個portoflio其中有4個圖像。所以它顯示圖像,我想在懸停時顯示Github徽標的圖像。

我已經發現了這一點:

a:hover:before { 
    content: ''; 
    display: block; 
    background: rgba(255, 0, 0, .5); /* your background */ 
    width: 500px; 
    height: 500px; 
    position: absolute; 
    top: 0; 
    right: 0; 
} 

但它需要的寬度和高度的。我的圖片沒有相同的高度,所以我需要一個適合圖片懸停的css/jQuery/angular代碼。

謝謝!

+1

嘗試:'寬度:100%;身高:100%'。 – dfsq 2014-11-08 15:03:27

+0

將懸停功能附加到父容器,然後交換圖像,類似於'.parent:hover .child {display:inline}'等。 – adeneo 2014-11-08 15:03:31

+0

設置高度:自動寬度:xxxpx,等於其他徽標 – 2014-11-08 15:06:54

回答

3

試試這個,它會一直覆蓋它的父母。您可以編輯背景位置以適合您的需求。

a:hover:before { 
     content: ''; 
     display: block; 
     background: url('img-path.png') no-repeat; 
     background-position: right bottom; 
     width: 100%; 
     height: 100%; 
     position: absolute; 
     top: 0; 
     right: 0; 
    } 

編輯:的盤旋一個標籤應使用position: relative;

+0

是的!我忘了它,但肯定我有::'a:{position:relative;}'感謝它的工作,我沒有想到100%:) – 2014-11-08 15:08:35

+0

如果它工作認爲接受答案! – Ragnar 2014-11-08 15:17:23

+0

我必須等待幾分鐘才能接受它 – 2014-11-08 15:30:35