Skip to content

Instantly share code, notes, and snippets.

@iksi
Last active February 8, 2018 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iksi/89d4c9a21a74798b9ece8540bc8d9826 to your computer and use it in GitHub Desktop.
Save iksi/89d4c9a21a74798b9ece8540bc8d9826 to your computer and use it in GitHub Desktop.
maintain ratio with svg (hack)
<style>
.embed {
position: relative;
}
.embed__ratio {
display: block
}
.embed__content {
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;
}
</style>
<div class="embed">
<svg class="embed__ratio" viewbox="0 0 4 3" display="none"></svg>
<img class="embed__content" src="broken.jpg" alt>
</div>
@iksi
Copy link
Author

iksi commented Feb 8, 2018

simpler way of maintaining ratio without using inline styles. the svg initially has display="none" purely to hide it when no stylesheet gets loaded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment