Skip to content

Instantly share code, notes, and snippets.

@demsone
Created July 4, 2013 06:14
Show Gist options
  • Save demsone/5925272 to your computer and use it in GitHub Desktop.
Save demsone/5925272 to your computer and use it in GitHub Desktop.
Centering Percentage Width/Height Elements
body {
background: #900;
}
.box {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 70%;
height: 80%;
padding: 20px;
background: red;
color: white;
text-align: center;
box-shadow: 0 0 30px rgba(0, 0, 0, 0.2);
}
<div class="box">
Percentage sized and still centered.
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment