jquery - 在 div 悬停效果上显示图像

标签 jquery html css hover

有许多插件会在将鼠标悬停在图像上时显示图像标题(例如:http://tympanus.net/Tutorials/CaptionHoverEffects/index4.html)。

我想达到相反的效果,即当鼠标悬停在包含文本的 div 上时,图像应该出现。谁能帮我做同样的事情?

最佳答案

我假设您正在使用 html5,如果是这样,您应该使用适合您内容上下文的标签:

<figure>
    <img src="http://placekitten.com/200/100" />
    <figcaption>Test message</figcaption>
</figure>

和CSS

figure {
    position: relative;
    display: inline-block;
}

figcaption {
    display: none;
    position: absolute;
    left: 0;
    bottom: 5px;
    right: 0;
    background-color: rgba(0,0,0,.15);
}

figure:hover img {
    opacity: .7;
}

figure:hover figcaption {
    display: block;
}

关于jquery - 在 div 悬停效果上显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36176499/

相关文章:

java - 使用 Linkify.addLinks 结合 Html.fromHtml

html - <h1> 图片前后重复?

javascript - 如果按下按钮打开类/窗口

css - 你能在 CSS 中设置边框不透明度吗?

html - 当所有子项都有 flex 属性时,父项的 justify-content 是否重要?

jquery - 这个 jquery 函数中的 this 等于什么?

javascript - Jquery Accordion 不会保持折叠状态

javascript - jQuery Ajax 竞争条件最佳实践

javascript - 在jquery中使用for循环(.each)

css - CSS 中带有 100% 和按钮的一行输入