html - 使用 CSS 使图像消失并在悬停后出现另一个图像

标签 html css hover

当鼠标悬停在#pic3 上时,我希望#pic3 消失而#pic4 出现在它的位置。

CSS:

#pic3{
max-width: 800px;
max-height: 500px;
}

#pic4{
max-width:800px;
max-height: 500px;
display:none;
}

#pic4:hover{
max-width:800px;
max-height: 500px;
opacity:1;
}

HTML

<div class="maps1">
    <img id="pic3" src="chicago.png">
    <img id="pic4" src="chicago2.png">
</div>

最佳答案

试试这个:

.maps1 #pic3 {display:inline-block;}
.maps1 #pic4 {display:none;}
.maps1:hover #pic3 {display: none;}
.maps1:hover #pic4 {display: inline-block;}

当然,如果您的实际站点上的 maps1 中还有任何其他内容,则效果不佳。

关于html - 使用 CSS 使图像消失并在悬停后出现另一个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20709620/

相关文章:

CSS 覆盖没有出现在 <img> 上?

html - Mikeal 请求正文格式错误

javascript - 如何使用 jquery 从 <td> 中获取隐藏值

css - 字体替代品

css - 悬停效果在 Firefox 中显示背景颜色而不是 .jpeg

css - 用悬停的CSS改变不透明度SVG

html - 带有垂直对齐文本和字幕的圆形 div

asp.net - 在 ASP.NET 中动态设置元素属性的值

css - Angular ng-class加载背景图片速度慢?

javascript - 获取 div 标签内容并将其应用于 javascript 中的内联样式