Skip to content

Instantly share code, notes, and snippets.

@sarvar
Last active February 23, 2017 07:34
Show Gist options
  • Save sarvar/b02886d5786b8940ab10461338b26f86 to your computer and use it in GitHub Desktop.
Save sarvar/b02886d5786b8940ab10461338b26f86 to your computer and use it in GitHub Desktop.
Vertical Align img in Div
Version01
<div class="image-container">
<img src="http://placehold.it/100x100" />
</div>
.image-container {
width: 200px;
display: flex;
justify-content: center;
}
Version2
<div class=frame>
<span class="helper"></span><img src="http://jsfiddle.net/img/logo.png" height=250 />
</div>
/*css*/
.frame {
height: 25px; /* equals max image height */
width: 160px;
border: 1px solid red;
white-space: nowrap;
text-align: center; margin: 1em 0;
}
.helper {
display: inline-block;
height: 100%;
vertical-align: middle;
}
img {
background: #3A6F9A;
vertical-align: middle;
max-height: 25px;
max-width: 160px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment