A Pen by Xinjiang Shao on CodePen.
Created
August 21, 2017 01:59
-
-
Save soleo/d2d49d9d89d7c0362f9bb618fa206738 to your computer and use it in GitHub Desktop.
Vertically Center Things - Absolute Positioning
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 class="container"> | |
| <div class="element-center"> | |
| <img class="peapod-logo" src="https://www.peapod.com/shop/images/favicon/apple-icon-180x180.png" /> | |
| <h1 class="peapod-text"> | |
| Peapod | |
| </h1> | |
| </div> | |
| </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
| html,body{ | |
| margin:0; | |
| padding:0; | |
| width:100%; | |
| height:100%; | |
| display:block; | |
| } | |
| .container { | |
| background-color: #333; | |
| display: block; | |
| width: 100%; | |
| min-height: 100vh; | |
| } | |
| .element-center { | |
| position: absolute; | |
| top: 50%; | |
| left: 50%; | |
| width: 180px; | |
| height: 180px; | |
| margin-top: -90px; /* Half the height */ | |
| margin-left: -90px; /* Half the width */ | |
| } | |
| .peapod-text { | |
| color: #fff; | |
| font-family: sans-serif; | |
| text-align:center; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment