Created
August 29, 2014 21:41
-
-
Save felixkosmalla/40f441e58f03533f7691 to your computer and use it in GitHub Desktop.
DIVs with CSS powered aspect ratio. Based on the following stackoverflow answer http://stackoverflow.com/a/12121309/1337100
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
<div class="wrapper"> | |
<div class="content"> | |
</div> | |
</div> |
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
@height = 9%; | |
@width = 16%; | |
.wrapper{ | |
width:100%; | |
display:inline-block; | |
position:relative; | |
&:after{ | |
padding-top:@height/@width * 100%; | |
display:block; | |
content:''; | |
} | |
.content{ | |
position:absolute; | |
top: 0; bottom: 0; right: 0; left: 0; | |
//background-size:cover; // optional | |
//background-color:red; // optional | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Demo here: http://jsfiddle.net/xc2fbnzb/