Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

Bootstrap 5 提示框


提示框

提示框组件是一个小的弹出框,当用户将鼠标指针移到元素上时出现。


如何创建提示框

要创建提示框,请将 data-bs-toggle="tooltip" 属性添加到元素中。

使用 title 属性指定应在提示框中显示的文本

<button type="button" class="btn btn-primary" data-bs-toggle="tooltip" title="Hooray!">将鼠标悬停在我上面!</button>

注意:提示框必须使用 JavaScript 初始化才能工作。

以下代码将启用文档中的所有提示框

示例

<script>
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
  return new bootstrap.Tooltip(tooltipTriggerEl)
})
</script>
自己尝试 »

提示框定位

默认情况下,提示框将出现在元素的顶部。

使用 data-bs-placement 属性设置提示框在元素顶部、底部、左侧或右侧的位置

示例

<a href="#" data-bs-toggle="tooltip" data-bs-placement="top" title="Hooray!">悬停</a>
<a href="#" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Hooray!">悬停</a>
<a href="#" data-bs-toggle="tooltip" data-bs-placement="left" title="Hooray!">悬停</a>
<a href="#" data-bs-toggle="tooltip" data-bs-placement="right" title="Hooray!">悬停</a>
自己尝试 »


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.