Skip to content

Instantly share code, notes, and snippets.

@j-
Created March 1, 2018 05:14
Show Gist options
  • Save j-/93d2ed72ad61cf92b745d13927c04592 to your computer and use it in GitHub Desktop.
Save j-/93d2ed72ad61cf92b745d13927c04592 to your computer and use it in GitHub Desktop.
Fixed ratio element
<div class="outer">
<div class="middle">
<div class="inner">
Hello world
</div>
</div>
</div>
.outer {
/* Set this to whatever width you would like */
width: 85.60mm;
}
.middle {
/* Set this to the ratio of height:width */
padding-top: 63.0607476635514%; /* = 53.98mm / 85.60mm */
position: relative;
}
.inner {
border: 1px solid gold;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment