pure-modal
Version:
A lightweight, accessible, vanilla JavaScript modal component
123 lines (107 loc) • 2.04 kB
CSS
.modal {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 1050;
overflow: hidden;
outline: 0;
}
.modal-dialog {
max-width: 500px;
margin: 64px auto;
position: relative;
width: auto;
pointer-events: none;
}
.modal-content {
position: relative;
display: flex;
flex-direction: column;
width: 100%;
pointer-events: auto;
background-color: #fff;
background-clip: padding-box;
border: 1px solid rgba(0,0,0,.1);
border-radius: 4px;
outline: 0;
}
.modal-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
padding: 16px;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
}
.modal-body {
position: relative;
flex: 1 1 auto;
padding: 16px;
}
.modal-footer {
display: flex;
justify-content: flex-end;
padding: 16px;
}
.modal-title {
margin: 0;
line-height: 1.5;
}
.modal-close {
margin: 0;
padding: 0;
border: none;
width: 16px;
height: 16px;
cursor: pointer;
background: none;
font-size: 0;
}
.modal-backdrop {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 1040;
background-color: #000;
}
.modal-backdrop.in {
opacity: 0;
transition: opacity 350ms ease-in-out;
}
.modal-backdrop.out {
opacity: 0;
transition: opacity 350ms ease-in-out;
}
.modal-backdrop.is-open {
opacity: .5;
}
.modal.in .modal-dialog {
animation: scaleUp 350ms ease-in-out;
}
.modal.out .modal-dialog {
animation: scaleDown 350ms ease-in-out;
}
@keyframes scaleUp {
0% {
transform: scale(1.2);
opacity: 0;
}
100% {
transform: scale(1);
opacity: 1;
}
}
@keyframes scaleDown {
0% {
transform: scale(1);
opacity: 1;
}
100% {
transform: scale(1.2);
opacity: 0;
}
}