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 4 Toast


Bootstrap 4 吐司提示框

吐司提示框组件类似于警报框,在某些事件发生时(例如,用户点击按钮、提交表单等)只会显示几秒钟。

吐司提示框标题 5 分钟前
吐司提示框主体内容

如何创建吐司提示框

要创建吐司提示框,请使用 .toast 类,并在其中添加 .toast-header.toast-body

<div class="toast">
  <div class="toast-header">
    吐司提示框标题
  </div>
  <div class="toast-body">
    吐司提示框主体内容
  </div>
</div>

注意:吐司提示框必须使用 jQuery 初始化:选择指定的元素并调用 toast() 方法。

以下代码将显示文档中的所有“吐司提示框”

示例

<script>
$(document).ready(function(){
  $('.toast').toast('show');
});
</script>
亲自尝试 »

显示和隐藏吐司提示框

吐司提示框默认隐藏。使用 data-autohide="false" 属性使其默认显示。要关闭它,请使用 <button> 元素并添加 data-dismiss="toast"

示例

<div class="toast" data-autohide="false">
  <div class="toast-header">
    <strong class="mr-auto text-primary">吐司提示框标题</strong>
    <small class="text-muted">5 分钟前</small>
    <button type="button" class="ml-2 mb-1 close" data-dismiss="toast">&times;</button>
  </div>
  <div class="toast-body">
    吐司提示框主体内容
  </div>
</div>
亲自尝试 »

注意 mr-automl-2mb-1 类?它们用于添加特定的边距。您将在 Bootstrap 4 实用工具类章节 中了解更多信息。


完整的 Bootstrap 吐司提示框参考

有关所有吐司提示框选项、方法和事件的完整参考,请访问我们的 Bootstrap JS 吐司提示框参考


×

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.