Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jocubeit
Created March 18, 2019 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jocubeit/79654ed526693ee3784cb37d92d62774 to your computer and use it in GitHub Desktop.
Save jocubeit/79654ed526693ee3784cb37d92d62774 to your computer and use it in GitHub Desktop.
Pure CSS Modal
%input#button{type:"checkbox"}
%label{for:"button"} Click Me!
%div.modal
%div.content Pure CSS Modal! No JS!

Pure CSS Modal

Essentially, I am using the input's checked pseudo class to manipulate the styles of the modal and label using sibling selectors.

A Pen by Mark Holmes on CodePen.

License.

html,
body {
height: 100%;
margin: 0;
padding: 0;
width: 100%;
}
.modal {
background: dodgerblue;
height: 1px;
overflow: hidden;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
transition: width 0.5s ease 0.5s,
height 0.5s ease;
width: 0;
}
.content {
color: transparent;
font-family: 'Consolas', arial, sans-serif;
font-size: 2em;
position: absolute;
top: 50%;
text-align: center;
transform: translate3d(0,-50%,0);
transition: color 0.5s ease;
width: 100%;
}
label {
color: dodgerblue;
cursor: pointer;
font-family: 'Consolas', arial, sans-serif;
font-size: 2em;
position: fixed;
left: 50%;
top: 50%;
text-transform: uppercase;
transform: translate(-50%, -50%);
transition: color 0.5s ease 0.5s;
}
input {
cursor: pointer;
height: 0;
opacity: 0;
width: 0;
&:focus {
outline: none;
}
}
input:checked {
height: 40px;
opacity: 1;
position: fixed;
right: 20px;
top: 20px;
z-index: 1;
-webkit-appearance: none;
width: 40px;
&::after,
&:before {
border-top: 1px solid #FFF;
content: '';
display: block;
position: absolute;
top: 50%;
transform: rotate(45deg);
width: 100%;
}
&::after {
transform: rotate(-45deg);
}
}
input:checked + label {
color: #FFF;
transition: color 0.5s ease,
}
input:checked ~ .modal {
height: 100%;
width: 100%;
transition: width 0.5s ease,
height 0.5s ease 0.5s;
.content {
color: #FFF;
transition: color 0.5s ease 0.5s;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment