A Pen by Timothy Long on CodePen.
Created
March 30, 2021 11:32
-
-
Save Polarhardboiled/a9d5aa9b710d2e3294985f06c25df458 to your computer and use it in GitHub Desktop.
Basic CSS-Only Modal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="container"> | |
<div class="interior"> | |
<a class="btn" href="#open-modal">👋 Basic CSS-Only Modal</a> | |
</div> | |
</div> | |
<div id="open-modal" class="modal-window"> | |
<div> | |
<a href="#" title="Close" class="modal-close">Close</a> | |
<h1>Voilà!</h1> | |
<div>A CSS-only modal based on the :target pseudo-class. Hope you find it helpful.</div> | |
<div><small>Check out</small></div> | |
<a href="https://aminoeditor.com" target="_blank">👉 Amino: Live CSS Editor for Chrome</div> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.modal-window { | |
position: fixed; | |
background-color: rgba(255, 255, 255, 0.25); | |
top: 0; | |
right: 0; | |
bottom: 0; | |
left: 0; | |
z-index: 999; | |
visibility: hidden; | |
opacity: 0; | |
pointer-events: none; | |
transition: all 0.3s; | |
&:target { | |
visibility: visible; | |
opacity: 1; | |
pointer-events: auto; | |
} | |
& > div { | |
width: 400px; | |
position: absolute; | |
top: 50%; | |
left: 50%; | |
transform: translate(-50%, -50%); | |
padding: 2em; | |
background: white; | |
} | |
header { | |
font-weight: bold; | |
} | |
h1 { | |
font-size: 150%; | |
margin: 0 0 15px; | |
} | |
} | |
.modal-close { | |
color: #aaa; | |
line-height: 50px; | |
font-size: 80%; | |
position: absolute; | |
right: 0; | |
text-align: center; | |
top: 0; | |
width: 70px; | |
text-decoration: none; | |
&:hover { | |
color: black; | |
} | |
} | |
/* Demo Styles */ | |
html, | |
body { | |
height: 100%; | |
} | |
html { | |
font-size: 18px; | |
line-height: 1.4; | |
} | |
body { | |
font-family: apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, | |
Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; | |
font-weight: 600; | |
background-image: linear-gradient(to right, #7f53ac 0, #657ced 100%); | |
color: black; | |
} | |
a { | |
color: inherit; | |
} | |
.container { | |
display: grid; | |
justify-content: center; | |
align-items: center; | |
height: 100vh; | |
} | |
.modal-window { | |
& > div { | |
border-radius: 1rem; | |
} | |
} | |
.modal-window div:not(:last-of-type) { | |
margin-bottom: 15px; | |
} | |
small { | |
color: lightgray; | |
} | |
.btn { | |
background-color: white; | |
padding: 1em 1.5em; | |
border-radius: 1rem; | |
text-decoration: none; | |
i { | |
padding-right: 0.3em; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment