Skip to content

Instantly share code, notes, and snippets.

@WinterSilence
Last active September 4, 2020 11:57
Show Gist options
  • Save WinterSilence/41e4c7a6a2436571b376 to your computer and use it in GitHub Desktop.
Save WinterSilence/41e4c7a6a2436571b376 to your computer and use it in GitHub Desktop.
CSS padding hack for create block with responsive square image
/* Example:
<div class="thumbnail">
<div class="square-box">
<a href="#"><img src="..." class="img-responsive" alt="..."></a>
</div>
</div>
*/
.square-box {
display: table;
position: relative;
padding-bottom: 100%;
width: 100%;
height: 0;
overflow: hidden;
}
.square-box .img-responsive {
display: table-cell;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: auto;
text-align: center;
vertical-align: middle;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment