Skip to content

Instantly share code, notes, and snippets.

@sushicodeur
Created July 24, 2015 10:04
Show Gist options
  • Save sushicodeur/64d607231ff47741abb8 to your computer and use it in GitHub Desktop.
Save sushicodeur/64d607231ff47741abb8 to your computer and use it in GitHub Desktop.
SCSS Image Ratio
@function pxtoem($target, $context:16px) {
@return ($target / $context) + 0em;
}
.entry-attachment { // Image ratio 135x180
$w: 135px;
$h: 180px;
$ratio: 100/($w/$h);
padding-top: $ratio;
display: block;
overflow: hidden;
position: relative;
width: pxtoem($w);
height: pxtoem($h);
background: url(images/logo.png) center center no-repeat; // Placeholder if no image
background-size: 50%;
img {
display: block;
min-width: 100%;
min-height: 100%;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment