HTML 解决方案
要在悬停时添加文本,我们需要使用 title 属性。
在这个片段中,我们将在 <div>、<span>、<abbr> 和 <p> 元素上使用它。
使用 <div> 元素在悬停时添加文本的示例:
<!DOCTYPE html> <html> <head> <title>文档的标题</title> </head> <body> <h2>Example</h2> <div title="This is a mouseover text!">将鼠标悬停在这上面</div> </body> </html>
使用 <span> 元素在悬停时添加文本的示例:
<!DOCTYPE html> <html> <head> <title>文档的标题</title> </head> <body> <h2>Example</h2> <span title="Hello world!">将鼠标悬停在这上面</span> </body> </html>
使用 <abbr> 和 <p> 元素在悬停时添加文本的示例:
<!DOCTYPE html> <html> <head> <title>文档的标题</title> </head> <body> <h2>Example</h2> <abbr title="Hypertext Markup Language">HTML</abbr> <p title="Hello world">Hover this one</p> </body> </html>
可以在没有 Javascript 甚至没有 CSS 的情况下添加鼠标悬停文本描述。
让我们看看如何仅使用 HTML 来做到这一点。
日期:2020-06-02 22:15:04 来源:oir作者:oir