console
(function(){
var alertsDismissible = Array.prototype.slice.call(document.querySelectorAll('.alert-dismissible'));
alertsDismissible.forEach(function(alertDismissible){
var close = alertDismissible.querySelector('.close');
if (!close){
return ;
}
close.onclick = function(){
alertDismissible.classList.remove('show');
setTimeout(function(){
alertDismissible.parentElement.removeChild(alertDismissible);
},500)
};
});
})();
<div class="alert alert-warning alert-dismissible show" role="alert">
<strong>Holy guacamole!</strong> You should check in on some of those fields below. <a href="" class="alert-link">this is a link</a>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<strong>Holy guacamole!</strong> You should check in on some of those fields below. <a href="" class="alert-link">this is a link</a>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="alert alert-success" role="alert">
<h4 class="alert-heading">Well done!</h4>
<p>Aww yeah, you successfully read this important alert message. This example text is going to run a bit longer so that you can see how spacing within an alert works with this kind of content.</p>
<hr>
<p class="mb-0">Whenever you need to, be sure to use margin utilities to keep things nice and tidy.</p>
</div>
$white: #fff !default;
$gray-100: #f8f9fa !default;
$gray-200: #e9ecef !default;
$gray-300: #dee2e6 !default;
$gray-400: #ced4da !default;
$gray-500: #adb5bd !default;
$gray-600: #6c757d !default;
$gray-700: #495057 !default;
$gray-800: #343a40 !default;
$gray-900: #212529 !default;
$black: #000 !default;
$grays: () !default;
$grays: map-merge((
"100": $gray-100,
"200": $gray-200,
"300": $gray-300,
"400": $gray-400,
"500": $gray-500,
"600": $gray-600,
"700": $gray-700,
"800": $gray-800,
"900": $gray-900
), $grays);
$blue: #007bff !default;
$indigo: #6610f2 !default;
$purple: #6f42c1 !default;
$pink: #e83e8c !default;
$red: #dc3545 !default;
$orange: #fd7e14 !default;
$yellow: #ffc107 !default;
$green: #28a745 !default;
$teal: #20c997 !default;
$cyan: #17a2b8 !default;
$colors: () !default;
$colors: map-merge((
"blue": $blue,
"indigo": $indigo,
"purple": $purple,
"pink": $pink,
"red": $red,
"orange": $orange,
"yellow": $yellow,
"green": $green,
"teal": $teal,
"cyan": $cyan,
"white": $white,
"gray": $gray-600,
"gray-dark": $gray-800
), $colors);
$primary: $blue !default;
$secondary: $gray-600 !default;
$success: $green !default;
$info: $cyan !default;
$warning: $yellow !default;
$danger: $red !default;
$light: $gray-100 !default;
$dark: $gray-800 !default;
$theme-colors: () !default;
$theme-colors: map-merge((
"primary": $primary,
"secondary": $secondary,
"success": $success,
"info": $info,
"warning": $warning,
"danger": $danger,
"light": $light,
"dark": $dark
), $theme-colors);
$alert-margin-bottom: 1rem;
$alert-padding-x: 1.25rem;
$alert-padding-y: .75rem;
$alert-border-radius: .25rem;
$alert-background-color-level: -10;
$alert-border-color-level: -6;
$alert-front-color-level: 6;
@function theme-color-level($color-name, $level){
$base-color : if($level < 0, #fff, #000);
$level : abs($level);
@return mix($base-color, map-get($theme-colors, $color-name), $level * 8% )
}
.alert{
position: relative;
padding: $alert-padding-y $alert-padding-x;
margin-bottom: $alert-margin-bottom;
}
.alert-dismissible{
.close{
position: absolute;
right: 0; top: 0;
padding: $alert-padding-y $alert-padding-x/ 2;
margin: 0;
}
}
@each $color-name, $color-value in $theme-colors{
.alert-#{$color-name}{
$front-color:theme-color-level($color-name, $alert-front-color-level);
color: theme-color-level($color-name, $alert-front-color-level);
background: theme-color-level($color-name, $alert-background-color-level);
.alert-link{
color: darken($front-color, 10%);
font-weight: 700;
text-decoration: none;
}
hr{
border: 0;
border-top: 1px solid theme-color-level($color-name, $alert-border-color-level );
}
}
}
.fade{
transition: opacity ease .5s;
opacity: 0;
&.show{
opacity: 1;
}
}
.close{
font-size: 1.5rem;
line-height: 1rem;
opacity: .5;
&:hover, &:focus{
opacity: .7;
}
}
.close:not(disabled):not(.disabled){
cursor: pointer;
}
button.close{
padding:0;
border: 0;
background: transparent;
}