Skip to content

Instantly share code, notes, and snippets.

@joby-lol
Created October 24, 2014 21:40
Show Gist options
  • Save joby-lol/a16924c630055cd1b296 to your computer and use it in GitHub Desktop.
Save joby-lol/a16924c630055cd1b296 to your computer and use it in GitHub Desktop.
A Pen by Joby Elliott.

CSS-centered modal

Pure-CSS centering of a box, both horizontally and vertically. No javascript required, works with any markup.

A Pen by Joby Elliott on CodePen.

License.

<div class="container">
<div class="centered">
Centered box, you can put whatever content
you want in here, and it stays centered!
No JS required, and super-clean markup.
</div>
</div>
/*
THERE IS NO JS!
*/
.container {
position:fixed;
top:0;
left:0;
right:0;
bottom:0;
background:#000;
text-align:center;
}
.centered {
padding:5px;
background:#eee;
border-radius:5px;
display:inline-block;
vertical-align:middle;
max-width:400px;
margin:10px;
}
.container:before {
content:"";
display:inline-block;
width:0;
height:100%;
vertical-align:middle;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment