Skip to content

Instantly share code, notes, and snippets.

@robertocarroll
Created December 14, 2017 17:31
Show Gist options
  • Save robertocarroll/e87a5eb1a29f605940840858f0966129 to your computer and use it in GitHub Desktop.
Save robertocarroll/e87a5eb1a29f605940840858f0966129 to your computer and use it in GitHub Desktop.
Centre image in a div with flexbox
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