Last active
September 4, 2020 11:57
-
-
Save WinterSilence/41e4c7a6a2436571b376 to your computer and use it in GitHub Desktop.
CSS padding hack for create block with responsive square image
This file contains 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
/* 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