Skip to content

Instantly share code, notes, and snippets.

@soleo
Created August 21, 2017 01:59
Show Gist options
  • Select an option

  • Save soleo/d2d49d9d89d7c0362f9bb618fa206738 to your computer and use it in GitHub Desktop.

Select an option

Save soleo/d2d49d9d89d7c0362f9bb618fa206738 to your computer and use it in GitHub Desktop.
Vertically Center Things - Absolute Positioning
<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>
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