Skip to content

Instantly share code, notes, and snippets.

@linlymatsumura
Last active February 20, 2017 02:38
Show Gist options
  • Save linlymatsumura/cf9412a4ed4d53e1734b6e1696d7c265 to your computer and use it in GitHub Desktop.
Save linlymatsumura/cf9412a4ed4d53e1734b6e1696d7c265 to your computer and use it in GitHub Desktop.
Markup and styling to fit an image of unknown size into a certain rectangle
<style>
figure{
width: /*WIDTH*/;
height: /*HEIGHT*/;
overflow: hidden;
position: relative;
margin: 0;
padding: 0;
float: left;
}
figure:before{
content:'no image';
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
z-index: 0;
}
img{
width: /*ZOOM*/;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
z-index: 1;
}
</style>
<figure>
<img src="...">
</figure>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment