Skip to content

Instantly share code, notes, and snippets.

@JohannesMP
Created May 16, 2013 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohannesMP/5593763 to your computer and use it in GitHub Desktop.
Save JohannesMP/5593763 to your computer and use it in GitHub Desktop.
Template: aspect-ratio locked Divs floating to center with outline
/**
* Template: aspect-ratio locked Divs floating to center with outline
*/
body {
margin: 80px;
padding: 0;
}
.image-grid {
text-align: center;
font-size: 0; /* removes default horizontal spacing on inline-block */
}
.image-grid > * {
vertical-align: top; /* removes default vertical spacing on inline-block */
display: inline-block;
}
.image-wrapper {
width: 100%;
max-width: 400px;
}
.image-content {
width:100%;
height:0;
padding-top:66.666%; /* 3x2 aspect ratio */
background-image: url(http://i.imgur.com/VkUpwPi.png);
background-repeat: no-repeat;
background-position: center;
background-size: 100% auto;
position: relative; /* necessary to keep the position: absolute contained*/
}
.image-overlay {
position: absolute;
top: 0; right: 0; bottom: 0; left: 0;
/*background: url(http://i.imgur.com/HeYHtzI.png);*/
background-repeat: no-repeat;
background-size: 100% 100%;
border: 5px solid rgba(0,0,0,0.5);
}
<div class="image-grid">
<div class="image-wrapper">
<div class="image-content">
<div class="image-overlay"></div>
</div>
</div>
<div class="image-wrapper">
<div class="image-content">
<div class="image-overlay"></div>
</div>
</div>
<div class="image-wrapper">
<div class="image-content">
<div class="image-overlay"></div>
</div>
</div>
</div>
// alert('Hello world!');
{"view":"separate","fontsize":"80","seethrough":"","prefixfree":"1","page":"all"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment