Skip to content

Instantly share code, notes, and snippets.

@ozrabal
Created June 15, 2016 18:26
Show Gist options
  • Save ozrabal/a32e49deac35c22f487675f87fe4010c to your computer and use it in GitHub Desktop.
Save ozrabal/a32e49deac35c22f487675f87fe4010c to your computer and use it in GitHub Desktop.
NrrRQy
<div class="centered">
<div class="logo">
<img src="http://placehold.it/350x350">
</div>
<div class="caption">
<p>Percentage sized and still centered.</p>
</div>
</div>
body {
background: #900;
}
.logo {
height: 100%;
position: relative;
}
img {
//height: 100%;
max-width: 100%;
max-height: 100%;
position: relative;
}
.caption{
display: block;
position: relative;
padding:0;
background: #ccc;
margin-top: 25px;
}
p{
margin: 0;
padding: 10px;
}
.centered {
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