Skip to content

Instantly share code, notes, and snippets.

@joewanko
Last active April 7, 2017 09:02
Show Gist options
  • Save joewanko/e190352329ec693d932e to your computer and use it in GitHub Desktop.
Save joewanko/e190352329ec693d932e to your computer and use it in GitHub Desktop.
SCSS Responsive height to width ratio trick.
.item {
background-attachment: inherit;
background-position: center;
background-size: cover;
display: inline-block;
height: auto;
position: relative;
width: 100%;
&::before {
content: '';
display: block;
padding-top: 50%; // H / W * 100% (Fallback)
padding-top: calc(100 / 200 * 100%); // H / W * 100%
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment