Last active
February 20, 2017 02:38
-
-
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
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
<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