Skip to content

Instantly share code, notes, and snippets.

@ericwwsun
Created June 16, 2014 16:29
Show Gist options
  • Save ericwwsun/ea3e73be4a77b997563f to your computer and use it in GitHub Desktop.
Save ericwwsun/ea3e73be4a77b997563f to your computer and use it in GitHub Desktop.
[CSS] keeping ratio box
.square {
//width within the parent
width: 100%;
&:before {
content: "";
float: left;
//essentially the aspect ratio. 100% means the
//div will remain 100% as tall as it is wide, or
//square in other words.
padding-bottom: 100%;
}
//this is a clearfix. you can use whatever
//clearfix you usually use, add
//overflow:hidden to the parent element,
//or simply float the parent container.
&:after {
content: "";
display: table;
clear: both;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment