Created
August 10, 2013 02:04
-
-
Save nladart/6198702 to your computer and use it in GitHub Desktop.
A CodePen by Chris Coyier. Percentage sized and still centered - Translate() has to be used instead of negative top margin, because that is based on width which doesn't work.
This file contains hidden or 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> | |
Percentage sized and still centered. | |
</div> |
This file contains hidden or 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
body { | |
background: #900; | |
} | |
div { | |
position: absolute; | |
left: 50%; | |
top: 50%; | |
transform: translate(-50%, -50%); | |
/* | |
This doesn't work | |
margin-left: -25%; | |
margin-top: -25%; | |
*/ | |
width: 40%; | |
height: 50%; | |
padding: 20px; | |
background: red; | |
color: white; | |
text-align: center; | |
box-shadow: 0 0 30px rgba(0, 0, 0, 0.2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment