Last active
September 11, 2018 17:07
-
-
Save sandeepsuvit/66d3cc6c1d7d5617f30ed6001586414f to your computer and use it in GitHub Desktop.
Fit image inside a div using css flex properties
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
<div class="img-container"> | |
<img class="img-to-fit" src="https://images.pexels.com/photos/8633/nature-tree-green-pine.jpg" /> | |
</div> |
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
.img-container { | |
width: 150px; | |
height: 150px; | |
border: 2px solid red; | |
justify-content: center; | |
display: flex; | |
flex-direction: row; | |
overflow: hidden; | |
.img-to-fit { | |
flex: 1; | |
height: 100%; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment