Skip to content

Instantly share code, notes, and snippets.

@leepettijohn
Last active April 16, 2019 14:05
Show Gist options
  • Save leepettijohn/8a9742915d3a28dcdce00b43b841fa7b to your computer and use it in GitHub Desktop.
Save leepettijohn/8a9742915d3a28dcdce00b43b841fa7b to your computer and use it in GitHub Desktop.
vertically align divs and images
<!-- source: http://jsfiddle.net/kizu/4RPFa/4570/ -->
<!-- my test: https://jsfiddle.net/leepettijohn/fdor13vd/ -->
<style>
.frame {
height: 100px; /* equals max image height */
width: 160px;
border: 1px solid red;
white-space: nowrap;
text-align: center; margin: 1em 0;
}
.middle{
display:inline;
vertical-align:middle;
}
.helper {
display: inline-block;
height: 100%;
vertical-align: middle;
}
img {
background: #3A6F9A;
vertical-align: middle;
max-height: 25px;
max-width: 160px;
}
</style>
<div class=frame>
<span class="helper"></span><div class="middle" >text</div>
</div>
<div class=frame>
<span class="helper"></span><img src="http://jsfiddle.net/img/logo.png" height=25 />
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment