Created
December 14, 2017 17:31
-
-
Save robertocarroll/e87a5eb1a29f605940840858f0966129 to your computer and use it in GitHub Desktop.
Centre image in a div with flexbox
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
http://jsfiddle.net/danield770/Ld8bcc0p/1/ | |
div.do_not_define_height { | |
display: flex; | |
justify-content: center; | |
/* align horizontal */ | |
align-items: center; | |
/* align vertical */ | |
width: 100%; | |
height: 100%; | |
} | |
img { | |
width: 80%; | |
height: auto; | |
} | |
<div style="border: 1px solid green; width: 80vw; height: 80vw;"> | |
<div class="do_not_define_height"> | |
<img alt="No, he'll be an engineer." src="http://placehold.it/350x150" /> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment