如何使多个bootstrap toast对齐为网格?

问题描述 投票:-1回答:2

如何制作多个Bootstrap Toast,如并排和从上到下?

链接供参考:https://getbootstrap.com/docs/4.2/components/toasts/

<div aria-live="polite" aria-atomic="true" style="position: relative; min-height: 200px;">

<!-- Then put toasts within -->
<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
  <div class="toast-header">
    <img src="..." class="rounded mr-2" alt="...">
    <strong class="mr-auto">Bootstrap</strong>
    <small class="text-muted">just now</small>
    <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">
    See? Just like this.
  </div>
</div>

<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
  <div class="toast-header">
    <img src="..." class="rounded mr-2" alt="...">
    <strong class="mr-auto">Bootstrap</strong>
    <small class="text-muted">2 seconds ago</small>
    <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">
    Heads up, toasts will stack automatically
  </div>
</div>

html css bootstrap-4 toast
2个回答
-1
投票

正如Bootstrap文档中所述:

“在您需要时使用自定义CSS放置祝酒词...您也可以使用flexbox实用程序来水平和/或垂直对齐吐司”

所以,你可以将Toasts放在绝对定位的flexbox div中。例如,这里是右对齐的堆叠Toasts ......

<div class="position-absolute w-100 d-flex flex-column align-items-end">
    <div class="w-25">
        <div class="toast ml-auto" role="alert" data-delay="1000" data-autohide="true">
            ...
        </div>
        <div class="toast ml-auto" role="alert" data-delay="3000" data-autohide="true">
            ...
        </div>
        <div class="toast ml-auto" role="alert" data-delay="5000" data-autohide="true">
            ...
        </div>
    </div>
</div>

flexbox有很多布局选项:

垂直堆叠:https://www.codeply.com/go/3ZvZa9b8Im 并排:https://www.codeply.com/go/GFMde2ritI 3x3网格:https://www.codeply.com/go/lj8GTFjvuK


-1
投票

看一下这个

<style>
#toast-container toast { width: 33%; }
</style>
<div aria-live="polite" aria-atomic="true" style="position: relative; min-height: 200px;" id="toast-container" class="d-flex flex-wrap">
    <!-- Then put toasts within -->
    <div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
        <div class="toast-header">
            <img src="..." class="rounded mr-2" alt="...">
            <strong class="mr-auto">Bootstrap</strong>
            <small class="text-muted">just now</small>
            <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">
            See? Just like this.
        </div>
    </div>
    <div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
        <div class="toast-header">
            <img src="..." class="rounded mr-2" alt="...">
            <strong class="mr-auto">Bootstrap</strong>
            <small class="text-muted">2 seconds ago</small>
            <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">
            Heads up, toasts will stack automatically
        </div>
    </div>
    <div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
        <div class="toast-header">
            <img src="..." class="rounded mr-2" alt="...">
            <strong class="mr-auto">Bootstrap</strong>
            <small class="text-muted">2 seconds ago</small>
            <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">
            Heads up, toasts will stack automatically
        </div>
    </div>
    <div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
        <div class="toast-header">
            <img src="..." class="rounded mr-2" alt="...">
            <strong class="mr-auto">Bootstrap</strong>
            <small class="text-muted">2 seconds ago</small>
            <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">
            Heads up, toasts will stack automatically
        </div>
    </div>
    <div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
        <div class="toast-header">
            <img src="..." class="rounded mr-2" alt="...">
            <strong class="mr-auto">Bootstrap</strong>
            <small class="text-muted">2 seconds ago</small>
            <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">
            Heads up, toasts will stack automatically
        </div>
    </div>
</div>
© www.soinside.com 2019 - 2024. All rights reserved.