html - 带有鼠标悬停文本的可链接图像
问题描述
当我鼠标悬停时,我想让这个可链接的图像在弹出框中有一个文本(不是 w3schools 上的弹出类型,我想要一个经典的黄色框)。我试着这样做
<div class="folder1">
<a href="yourlinkhere" target="_self" >
<img src="https://78.media.tumblr.com/c00202bad8ae39931e34a7efa861d18b/tumblr_p70bjja6xI1x5vw3ao1_500.png" height="46" width="57"
title="This is some text I want to display." </a>
</div>
在链接中打开页面效果很好,但是当我将鼠标悬停在它上面时没有弹出框。有什么帮助吗?
解决方案
目前,您正在设置title
属性以在元素悬停时获取工具提示类型提示。如果这是您想要做的,但也许只是将文本框设置为黄色,我建议使用以下内容:
a {
color: #900;
text-decoration: none;
}
a:hover {
color: red;
position: relative;
}
a[data]:hover:after {
content: attr(data);
padding: 4px 8px;
color: rgba(0,0,0,0.5);
position: absolute;
left: 0;
top: 100%;
white-space: nowrap;
z-index: 2;
border-radius: 5px ;
background: rgba(0,0,0,0.5); /*Change this to yellow, or whatever background color you desire*/
}
<a data="This is the CSS tooltip showing up when you mouse over the link"href="#" class="tip">Link</a>
上面的代码由Peeyush Kushwaha在这篇文章中提供。只需将锚标记更改为您的图像标记,然后应用您认为合适的样式。
如果通过“弹出”您正在寻找需要交互关闭的用户警报,您可以window.alert('text')
在 javascript 中与onmouseover
事件处理程序一起使用。
<img src="some_image.png" height="46px" width="57px" onmouseover="window.alert('Some Message')"/>
否则,如果您正在寻找在图像鼠标悬停时显示的另一个元素,您可以使用一些 javascript 在 img 鼠标悬停时显示 div 或段落(实际上是任何东西)。
function showDiv() {
document.getElementById('popupBox').style.display = 'block';
}
#popupBox {
display: none;
}
<img src="some_image.png" width="41px" height="57px" onmouseover="showDiv()"/>
<div id="popupBox">Some Popup Text</div>
推荐阅读
- linux - ulimit -a 输出和“cat /proc/PID/limits”有什么区别?
- python - 如何正确索引
- google-app-engine - 部署在 App Engine 上的带有 Hibernate 的 SpringBoot App 无法连接到 Cloud SQL
- linux - ucarp 选择主模式时 ARP 错误
- youtube - youtube iframe 播放列表无法隐藏每个视频的标题
- css - 滚动在 safari 上不起作用,但抓取滚动条确实有效
- linux - 如何在不克隆整台机器的情况下将 docker 迁移到另一台机器上
- sql - 在 Netezza Aginity 中显示 CRATE TABLE
- android - Google 在 android 上使用 firebase 登录一直失败
- elasticsearch - Elasticsearch 使用可选对象数组创建索引模板架构