Alerts
Basic dismissable and non-dismissable alerts container style utilities.
Examples (anchor)
The alerts expect the existence of basic reset styles for font styling and typography properties. The typography style module provides this but the styles should work with any reset/normalize document used.
Default (anchor)
Basic alert
Example HTML
<div class="alert">
<p>Basic alert</p>
</div>
<dialog class="alert" open>
<p>Dismissable alert!</p>
<form method="dialog">
<button><span>Close</span></button>
</form>
</dialog>
Fixed light and dark (anchor)
Basic alert!
Basic alert!
Example HTML
<div class="alert alert-light">
<p>Basic alert!</p>
</div>
<dialog class="alert alert-light" open>
<p>Dismissable alert!</p>
<form method="dialog">
<button><span>Close</span></button>
</form>
</dialog>
<div class="alert alert-dark">
<p>Basic alert!</p>
</div>
<dialog class="alert alert-dark" open>
<p>Dismissable alert!</p>
<form method="dialog">
<button><span>Close</span></button>
</form>
</dialog>
Using the module (anchor)
To use the module load the StyleMods scss
directory as follows (changing the path to suit the source files location as required) then include the Sass mixin anywhere below.
custom.scss
@use "stylemods/scss" as *;
@include alerts-css;
Source code (anchor)
See customizing for information about using the Sass and CSS variables in the source code to customize the styles, and Sass functionality (on the using StyleMods page) for other ways to use the variables to create custom styles.
alerts.scss
// ----------------------------------------------------------
// Alerts
// ----------------------------------------------------------
$alert-text-color: var(--alert-text, CanvasText) !default;
$alert-margin-bottom: var(--alert-mb, 1rem) !default;
$alert-padding-block: var(--alert-py, 0.66rem) !default;
$alert-padding-inline: var(--alert-px, 1rem) !default;
$alert-border-color: var(--alert-bd-color, color-mix(in srgb, CanvasText 15%, Canvas)) !default;
$alert-radius: var(--alert-radius, 0.188rem) !default;
$alert-background-color: var(--alert-bg, color-mix(in srgb, CanvasText 4%, Canvas)) !default;
// Icon options
$alert-close-icon: url("data:image/svg+xml,<svg viewBox='0 0 16 16' fill='currentColor' xmlns='http://www.w3.org/2000/svg'><path d='m2.47 3.53 1.06-1.06 4.47 4.47 4.47-4.47 1.06 1.06-4.47 4.47 4.47 4.47-1.06 1.06-4.47-4.47-4.47 4.47-1.06-1.06 4.47-4.47z'/></svg>") !default;
$alert-close-box-icon: url("data:image/svg+xml,<svg viewBox='0 0 16 16' fill='currentColor' xmlns='http://www.w3.org/2000/svg'><path d='m4.82 5.53s-0.354-0.354 0-0.707 0.707 0 0.707 0l2.47 2.47 2.47-2.47s0.354-0.354 0.707 0c0.354 0.354 0 0.707 0 0.707l-2.47 2.47 2.47 2.47s0.354 0.354 0 0.707c-0.354 0.354-0.707 0-0.707 0l-2.47-2.47-2.47 2.47s-0.354 0.354-0.707 0c-0.354-0.354 0-0.707 0-0.707l2.47-2.47zm-3.31-5.51c-0.911-0.0389-1.61 0.85-1.5 1.73 0.00311 4.3-0.00623 8.6 0.00467 12.9 0.0329 0.888 0.925 1.49 1.77 1.38 4.28-0.0031 8.57 0.0062 12.9-0.0047 0.888-0.0329 1.49-0.925 1.38-1.77-0.0031-4.28 0.0062-8.57-0.0047-12.9-0.0329-0.888-0.925-1.49-1.77-1.38h-12.7zm0 1h13c0.583-0.0209 0.508 0.598 0.5 0.998v12.5c0.0209 0.583-0.598 0.508-0.998 0.5h-12.5c-0.583 0.0209-0.508-0.598-0.5-0.998v-12.5c0.0112-0.281 0.181-0.553 0.5-0.5z'/></svg>") !default;
$alert-close-box-fill-icon: url("data:image/svg+xml,<svg viewBox='0 0 16 16' fill='currentColor' xmlns='http://www.w3.org/2000/svg'><path d='m2 0c-2 0-2 2-2 2v12c0 2 2 2 2 2h12c2 0 2-2 2-2v-12c0-2-2-2-2-2h-12zm3.08 4.67c0.249-0.0497 0.447 0.15 0.447 0.15l2.47 2.47 2.47-2.47s0.353-0.354 0.707 0c0.354 0.354 0 0.707 0 0.707l-2.47 2.47 2.47 2.47s0.354 0.353 0 0.707c-0.354 0.354-0.707 0-0.707 0l-2.47-2.47-2.47 2.47s-0.353 0.354-0.707 0c-0.354-0.354 0-0.707 0-0.707l2.47-2.47-2.47-2.47s-0.354-0.353 0-0.707c0.0884-0.0884 0.177-0.134 0.26-0.15z'/></svg>") !default;
// Close icon
$close-alert: $alert-close-icon !default;
@mixin alerts-css {
.alert {
color: $alert-text-color;
margin-block-end: $alert-margin-bottom;
padding-block: $alert-padding-block;
padding-inline: $alert-padding-inline;
border: 1px solid $alert-border-color;
border-radius: $alert-radius;
background-color: $alert-background-color;
}
.alert * {
margin-block-end: 0;
}
.alert[open] {
display: flex;
flex-wrap: wrap;
align-items: center;
position: relative;
inline-size: 100%;
max-inline-size: 100%;
margin: initial;
margin-block-end: $alert-margin-bottom;
padding-block: $alert-padding-block;
padding-inline-end: $alert-padding-inline;
transition: none;
}
.alert [method="dialog"] {
margin-inline-start: auto;
}
.alert [method="dialog"] button {
background-color: transparent;
border: none;
padding-block: 0.1rem;
padding-inline: 0.5rem;
margin-inline-start: auto;
}
.alert [method="dialog"] button:is(:hover, :focus, :active) {
background-color: transparent;
border: none;
}
.alert [method="dialog"] button:before {
--ico: var(--alert-text, CanvasText);
display: inline-block;
content: "";
block-size: 1em;
inline-size: 1em;
vertical-align: -.115em;
background-color: var(--ico);
mask-image: #{$close-alert};
mask-repeat: no-repeat;
}
.alert [method="dialog"] button span {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
overflow: hidden;
clip: rect(0,0,0,0);
white-space: nowrap;
}
.alert-light {
color-scheme: light;
}
.alert-dark {
color-scheme: dark;
}
} // End alerts-css