html - 将鼠标悬停在图像上以显示另一个图像

标签 html css

大家好,我有一个黑色图像,当用户将鼠标悬停在它上面时,我希望出现一个白色图像,但出于某种原因,每次我将鼠标悬停在黑色图像上时,什么都没有出现

HTML:

    <div class="col-xs-12 col-sm-6 col-md-3" align="center" class ="profile-image">
    <img alt="my image" class="img-about" src="Images/s4.fw.png">
    <span class="overlay"></span>
        <h2>Yoga</h2>
    </div>

CSS:

.profile-image:hover .overlay {
  position:absolute;
  width: 48px;
  height: 48px;
  z-index: 100;
  background: transparent url('Images/s4h.fw.png') no-repeat;
  cursor: pointer;
}

谢谢

最佳答案

也许您可以使用此代码作为替代品?它更简单..只需使用背景图像而不是颜色..

<!DOCTYPE html>
<html>
<head>
<style>
.col{
    margin:auto;
    height:200px;
    width:200px;
    background-color:blue;
}
.col:hover{
    background-color:yellow;
    cursor: pointer;
}
</style>

</head>
<body>

 <div class="col" align="center" >

        <h2>Yoga</h2>
    </div>
</body>
</html

关于html - 将鼠标悬停在图像上以显示另一个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45537796/

相关文章:

javascript - 使用 jquery 制作 div 动画

CSS - 不同领域的不同样式

javascript - Uncaught ReferenceError : Oncheckboxclicked is not defined at HTMLElement. onclick

javascript - 带有 uikit 的粘性图像

html - 显示 :table-cell on Firefox (21, OSX 问题)

javascript - 如何从基于模板的网站打印条形码?

html - 为什么 body 背景图像不显示?

html - IE导航后台问题

javascript - 隐藏和显示字段集

css - JavaFX CSS 中的 -fx-padding 和 -fx-label-padding 有什么区别?