代码之家  ›  专栏  ›  技术社区  ›  Junior

如何在右上角显示bootstrap 4.2 Toast?

  •  0
  • Junior  · 技术社区  · 6 年前

    我正试图利用 Bootstrap 4.2 Toast

    我尝试了下面的标记,正如它在文档中的boostrap示例中所示,但我无法让它显示出来。

    <!-- Toasts -->
    <div aria-live="polite" aria-atomic="true" style="position: relative;">
    
        <!-- Position it -->
        <div style="position: absolute; top: 3rem; right: 0;">
            <div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
                <div class="toast-header">
                    <strong class="mr-auto">Toast Title</strong>
                    <button type="button" class="ml-2 mb-1 close" data-dismiss="toast" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="toast-body">
                    Some Toast Body      
                </div>
           </div>
    
        </div>
    </div>
    

    这是一个 fiddler 用我的全部标记,但似乎无法显示祝酒词。

    我怎样才能举杯

    1 回复  |  直到 5 年前
        1
  •  5
  •   Carol Skelly    4 年前

    answer 右上角是祝酒词。您创建的原始小提琴(在编辑问题之前)不包括引导JS。

    Bootstrap docs ...

    “出于性能原因,祝酒会是可选的,因此 他们自己

    所以你需要像这样初始化它们。。。

    $('.toast').toast('show');
    

    此外,当您包括 相对的 position元素(就像在小提琴中一样)绝对元素相对于父元素,因此位于页面上其他内容的下方。删除相对父对象以使绝对Toast相对于整个页面。

    演示: https://codeply.com/go/AVBr2zUcue