要在 HTML 中设置鼠标悬停提示效果,可以使用title属性。该属性可应用于大多数 HTML 元素,包括链接、图像、段落等。当用户将鼠标悬停在带有title属性的元素上时,会显示一个文本框,其中包含定义的标题文本。
以下是一个示例,在一个链接元素上设置鼠标悬停提示效果:
<a href="https://www.example.com" title="This is a link to Example website">Example Website</a>
在上面的示例中,当用户将鼠标悬停在链接上时,会显示一个文本框,其中包含“ This is a link to Example website ”这段文本。
如果想要在段落或其他元素上设置鼠标悬停提示效果,可以将title属性添加到元素的起始标签中,如下所示:
<p title="This is a paragraph with a tooltip">This is a paragraph.</p>
<!DOCTYPE html>
<html>
<head>
<title>Tooltip Example</title>
</head>
<body>
<h1>Tooltip Example</h1>
<p>Hover over the <a href="https://www.example.com" title="This is a link to Example website"><strong>Example Website</strong></a> link to see a tooltip.</p>
<p title="This is a paragraph with a tooltip">Hover over this paragraph to see a tooltip.</p>
<pre><code><p title="This is a paragraph with a tooltip">Hover over this paragraph to see a tooltip.</p></code></pre>
</body>
</html>
在上面的示例中,我们在一个链接和一个段落上设置了鼠标悬停提示效果,并使用了pre标签来显示代码块。重要的关键词使用了strong标签来加粗,并使用了pre标签来突出显示代码块中的HTML元素。