Last active
August 29, 2015 14:23
-
-
Save teknotica/fca87e2bfb2391fa28ec to your computer and use it in GitHub Desktop.
SASS snippet to keep ratio of element
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
.wrapper { | |
display: inline-block; | |
position: relative; | |
&:after { | |
content: ""; | |
padding-top: 56.25%; // Use 100% for square ratio | |
display: block; | |
} | |
.inner { | |
position: absolute; | |
top: 0; | |
left: 0; | |
right: 0; | |
bottom: 0; | |
img { | |
display: block; | |
width: 100%; | |
height: 100% | |
} | |
} | |
} | |
/* | |
<!-- Example Markup --> | |
<div class="wrapper"> | |
<div class="inner"> | |
<h1>Keep ratio please</h1> | |
</div> | |
</div> | |
<div class="wrapper"> | |
<div class="inner"> | |
<img src="/images/image.jpg" alt="An image"> | |
</div> | |
</div> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment