Last active
November 2, 2015 23:41
-
-
Save patpaev/70c88040f95fd095c76b to your computer and use it in GitHub Desktop.
Resize to fit image in div, and center horizontally and vertically
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
/* answer: http://stackoverflow.com/a/31699529 */ | |
.container { | |
overflow: hidden; | |
width: 400px; | |
height: 300px; | |
position:relative | |
} | |
img { | |
position: absolute; | |
top: 0; | |
right: 0; | |
bottom: 0; | |
left: 0; | |
margin: auto; /* this centers image inside */ | |
width: 100%; /* this is to shrink the images of large width */ | |
height: auto; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment