我試圖讓文字在懸停時出現在表格單元格內。我希望文字保持隱藏狀態,直到我將它懸停在上面。我這樣做,但不知道如何使文本顯示爲純色(當我將鼠標懸停在單元格上時,它會降低其不透明度)。有什麼方法可以使用jQuery在所有內容上添加文本?我希望爲六個單元中的每一個都這樣做。我嘗試使用z-index來做到這一點,但它沒有奏效。懸停時透明背景上的文字
HTML
<div>
<a NAME="work">
<div class="samples">
<table>
<th>Pokemon</th>
<tr>
<td id = "squirtle">
<img src = "http://assets.pokemon.com/assets/cms2/img/pokedex/full//007.png">
</td>
<td><img src = "http://assets.pokemon.com/assets/cms2/img/pokedex/full//006.png"></td>
<td><img src = "http://assets.pokemon.com/assets/cms2/img/pokedex/full//001.png"></td>
</tr>
<tr>
<td><img src = "http://vignette3.wikia.nocookie.net/fantendo/images/a/a5/Pikachu_digital_art_pokemon_by_dark_omni-d5wotdb.png/revision/latest?cb=20141113035440"></td>
<td><img src = "https://upload.wikimedia.org/wikipedia/en/5/5f/Pok%C3%A9mon_Lugia_art.png"></td>
<td><img src = "http://vignette1.wikia.nocookie.net/pokemon/images/f/ff/Togepi.png/revision/latest?cb=20100731212849"</td>
</tr>
</table>
</div>
CSS
.samples table{
table-layout: fixed;
position: relative;
width: 100%;
}
.samples td img{
height:300px;
width: 300px;
position: center;
z-index:3;
}
.samples td{
text-align: center;
height: 300px;
width: 300px;
background-color: rgb(0,300,300);
padding: 0px;
margin: 0px;
border-color: 2px solid black;
}
.samples td#squirtle:hover p{
visibility: visible;
color: black;
opacity: 0.8;
}
.samples td:hover{
opacity: .7;
}
.samples td#squirtle p{
visibility: hidden;
}
jQuery的
$(".samples td img").click(function(){
$(this).text("squirtle rules");
})
imgs沒有文字內容......你需要定位包含圖像的父td,而不是圖像本身。 –