Last active
October 27, 2016 16:44
-
-
Save salt-istanbul/d38295e780c464f8fc52 to your computer and use it in GitHub Desktop.
Bootstrap Responsive Square & Rectangle
This file contains hidden or 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
div[class*="col-"] > .square-responsive, | |
span[class*="col-"] > .square-responsive, | |
ol[class*="col-"] > .square-responsive, | |
ul[class*="col-"] > .square-responsive, | |
li[class*="col-"] > .square-responsive{ | |
padding-bottom:100%; | |
} | |
div[class*="col-"] > .rect-responsive, | |
span[class*="col-"] > .rect-responsive, | |
ol[class*="col-"] > .rect-responsive, | |
ul[class*="col-"] > .rect-responsive, | |
li[class*="col-"] > .rect-responsive{ | |
padding-bottom:50%; | |
} | |
.square-responsive, | |
.rect-responsive{ | |
position:relative; | |
overflow:hidden; | |
} | |
.square-responsive > *, | |
.rect-responsive > *{ | |
position:absolute; | |
} | |
.square-responsive > .content, | |
.rect-responsive > .content { | |
width:100%; | |
height:100%; | |
} | |
/*usage | |
<div class="row"> | |
<div class="col-sm-6"> | |
<div class="square-responsive"> | |
<div class="content"> | |
Hello | |
</div> | |
</div> | |
</div> | |
<div class="col-sm-6"> | |
<div class="square-responsive"> | |
<div class="content"> | |
Hello | |
</div> | |
</div> | |
</div> | |
</div> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Amazing solution! Thanks a lot. But it seems it is not perfect. The rectangle part is higher then the squares. I tried reducing the 100% to around 97. At first it seems to work, but when you are scaling you will see that it does not align with the rest of the squares. Any solutions?