2017-05-08 72 views
0

比方說,我有一隻狗的形象。當用戶懸停在圖像上時,我該如何製作圖像,圖像消失,而是帶有「樹皮」的h1標籤?當鼠標懸停標籤時,如何將標籤更改爲不同的標籤?

+2

你可以有一個div容器,它裏面有兩個div的圖像和文字。根據您的需要顯示/隱藏。這是想法,你可以分享一些更好的幫助 – tech2017

+0

重疊文字上的圖像,然後在圖像上隱藏它的懸停風格。 – 4castle

+0

@techLove我從來沒有真的這樣想過。我會試試看看它是如何發展的。 – Miguel

回答

0

也許此代碼段可以是一個解決辦法

<html> 
 
<head> 
 
\t <style> 
 
\t \t #wrap { 
 
\t \t \t width: 128px; 
 
\t \t \t height: 128px; 
 
\t \t \t border: 2px solid black; 
 
\t \t \t display: inline-block; 
 
\t \t \t position: relative; 
 
\t \t } 
 
\t \t #img { 
 
\t \t \t width: 128px; 
 
\t \t \t position: absolute; 
 
\t \t \t z-index: 2; 
 
\t \t \t top: 0; 
 
\t \t \t transition: all 0.3s ease-in-out 0s; 
 
\t \t } 
 
\t \t #img:hover { 
 
\t \t \t opacity: 0; 
 
\t \t } 
 
\t </style> 
 
</head> 
 
<body> 
 

 
<div id="wrap"> 
 
\t <h1>Bark!</h1> 
 
\t <img id="img" src="https://www.iconexperience.com/_img/o_collection_png/green_dark_grey/256x256/plain/dog.png"> 
 
</div> 
 

 
</body> 
 
</html>

0

也許此代碼段可以指向你在正確的方向:

<html> 
<head> 
<style> 
img, h1 { 
     transition: all 0.3s ease-in-out 0s; 
} 
h1 { 
    display: none; 
} 
img:hover + h1 { 
    display: block; 
} 
h1:hover + img { 
    display: none; 
} 
img:hover { 
    display: none; 
} 
</style> 
</head> 
<body> 
<div> 
<img src="http://i.imgur.com/jsdLHHv.png" /> 
<h1>Bark</h1> 
</div> 
</body> 
0

這裏是一個非常簡單的例子。應該是不言自明的:

dog-barking-tag { 
 
    display: none; 
 
} 
 
parent:hover dog-barking-tag { 
 
    display: inline; /* or any other display value you need */ 
 
} 
 
parent:hover dog-image-tag { 
 
    display:none; 
 
}
<parent> 
 
    <dog-barking-tag> 
 
    &lt;::barking tag:: /> 
 
    </dog-barking-tag> 
 
    <dog-image-tag> 
 
    &lt;dog image tag /> 
 
    </dog-image-tag> 
 
</parent>

的 「替代品」 是在parent:hover完成。

0

您可以通過不同的方法實現此目的。對於我下面關於懸停在容器上的示例,它會更改「可見性」屬性。請參閱以下示例代碼。

.animal-cont{ 
 
\t \t \t width: 16%; 
 
     height: 120px; 
 
     border: 3px #ddd solid; 
 
     position: relative; 
 
     cursor: pointer; 
 
\t \t } 
 
    h1 { 
 
     left: 50% ; 
 
     top: 50%; 
 
     transform: translate(-50%,-50%); 
 
     margin: auto; 
 
\t \t \t position: absolute; 
 
     visibility: hidden; 
 
     color: #843f15; 
 
\t \t } 
 
    img { 
 
    max-width: 100%; 
 
    } 
 
    .animal-cont:hover > img { 
 
\t \t \t visibility: hidden; 
 
\t \t } 
 
    .animal-cont:hover > h1 { 
 
\t \t \t visibility: visible; 
 
\t \t }
<div class="animal-cont"> 
 
\t <h1>Bark!</h1> 
 
\t <img id="img" src=""> 
 
</div>

+0

謝謝。這一個運作良好。 – Miguel

相關問題