-1

I'm trying to show a bootstrap alert message as an overlay toast (so it auto hides, and is shown above other elements).

Problem: I have a spacing at the bottom of the toast, and cannot get rid of it: https://jsfiddle.net/dertqczw/

<div data-delay="30000" id="myToast" class="toast" role="alert" aria-live="assertive" aria-atomic="true" style="position:absolute; top:50px; left:50px;">
  <div class="toast-body">
     <div class="alert fade show alert-primary" role="alert">Success</div>
  </div>
</div>

//show toast with:
$("#myToast").toast('show');
 
/* get rid of toast styles */
.toast-body {
    padding: 0;
    font-size: 1rem;
}
.toast {
    border: none;
    background-color: inherit;
}
membersound
  • 81,582
  • 193
  • 585
  • 1,120

2 Answers2

1

Reset the margin on the .alert-primary

.alert-primary {
    margin: 0;
}

Fiddle


If you wish to remove the margin for all the alerts, target the .alert class;

.alert {
    margin: 0;
}

Fiddle


To only target .alert inside an toast; target all the child elements;

.toast-body .alert {
    margin: 0;
}

Fiddle

0stone0
  • 34,288
  • 4
  • 39
  • 64
1

Add this to your css:

#myToast .alert {
    margin-bottom: 0;
}

Or a more general solution:

.alert {
    margin-bottom: 0;
}

EDIT:

For only toast alerts:

.toast-body .alert {
    margin-bottom:0;
}

Compared to the other answer, this one is just slightly better due to the specificity of setting 'margin-bottom', which is what the OP wanted, instead of 'margin'.

Mythos
  • 1,378
  • 1
  • 8
  • 21