Toast is a brief, transient message that appears on the screen to provide feedback or notifications to users without interrupting their current activity.
<button class="c-toast__trigger">Make Toast</button>
<div class="c-toast">
Toast notification
<button class="c-toast__exit">+</button>
</div>
.c-toast {
width: 400px;
margin: auto;
display: flex;
justify-content: space-between;
align-items: center;
background-color: #64ffda;
color: #1a202c;
padding: 10px 15px;
border-radius: 5px;
position: fixed;
bottom: 0;
left: 0;
right: 0;
opacity: 0;
visibility: hidden;
transition: all 0.5s ease;
z-index: 150;
}
.c-toast.is-active {
bottom: 40px;
opacity: 1;
visibility: visible;
}
.c-toast__trigger {
background-color: #33aef7;
padding: 10px;
border-radius: 5px;
border: none;
cursor: pointer;
transition: all 0.2s ease;
}
.c-toast__trigger:hover {
background-color: #0889d5;
}
.c-toast__exit {
background-color: transparent;
font-size: 30px;
border: none;
transform: rotate(45deg);
cursor: pointer;
}
.c-toast {
width: 400px;
margin: auto;
display: flex;
justify-content: space-between;
align-items: center;
background-color: #64ffda;
color: #1A202C;
padding: 10px 15px;
border-radius: 5px;
position: fixed;
bottom: 0;
left: 0;
right: 0;
opacity: 0;
visibility: hidden;
transition: all 0.5s ease;
z-index: 150;
&.is-active {
bottom: 40px;
opacity: 1;
visibility: visible;
}
&__trigger {
background-color: #33aef7;
padding: 10px;
border-radius: 5px;
border: none;
cursor: pointer;
transition: all 0.2s ease;
&:hover {
background-color: darken(#33aef7, 15%);
}
}
&__exit {
background-color: transparent;
font-size: 30px;
border: none;
transform: rotate(45deg);
cursor: pointer;
}
}
const toast = document.querySelector('.c-toast');
const toastTrigger = document.querySelector('.c-toast__trigger');
const toastExit = document.querySelector('.c-toast__exit');
toastTrigger.addEventListener('click', () => {
toast.classList.add('is-active');
});
toastExit.addEventListener('click', () => {
toast.classList.remove('is-active');
});