Skip to content

Instantly share code, notes, and snippets.

@felixkosmalla
Created August 29, 2014 21:41
Show Gist options
  • Save felixkosmalla/40f441e58f03533f7691 to your computer and use it in GitHub Desktop.
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
<div class="wrapper">
<div class="content">
</div>
</div>
@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
}
}
@felixkosmalla
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment