In HTML, how can you make an image appear while you are hovering over text?(在 HTML 中,如何在将鼠标悬停在文本上时显示图像?)
问题描述
在 HTML 中,当我将鼠标悬停在特定文本部分上时,如何使图像出现(或变得可见)?我正在编写一个 HTML 应用程序,以下是我的代码:
In HTML, how can I cause an image to appear (or become visible) while I'm hovering over a specific section of text? I'm coding an HTML app, and the following is my code:
.plank1 {
position: static;
left: 80px;
top: 100px;
visibility: visible;
}
.plank1appear:hover .plank1{
visibility: visible;
}
推荐答案
要在将鼠标悬停在整段文本上时显示图像,您可以在 hover
上显示和隐藏图像:
To show an image when you hover over a whole section of text you can show and hide the image on hover
:
CSS
img{
display: none
}
p.one:hover + img{ //img is a sibling
display: block;
}
p.two:hover img{ //image is a child
display: block;
}
HTML
<p class="one">HOVER OVER ME - IMG IS SIBLING</p>
<img src="aHR0cDovL3d3dy5wbGFjZWNhZ2UuY29tLzEwMC8xMDA="/>
<p class="two">HOVER OVER ME -IMG IS CHILD
<img src="aHR0cDovL3d3dy5wbGFjZWNhZ2UuY29tLzEwMC8xMDA="/>
</p>
示例
如果您想将鼠标悬停在文本的特定部分上,您可以将文本包装在 span
中,并将图像设为该 span
的同级或子级:
If you want to hover over a specific part of the text, you can wrap the text in a span
and just make the image a sibling or child of that span
:
HTML
<p>This is some text. <span>HOVER OVER ME</span>
<img src="aHR0cDovL3d3dy5wbGFjZWNhZ2UuY29tLzEwMC8xMDA="/>
</p>
CSS
img{
display: none
}
span:hover + img{
display: block;
}
示例二
这篇关于在 HTML 中,如何在将鼠标悬停在文本上时显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 HTML 中,如何在将鼠标悬停在文本上时显示图像?


- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01