Skip to content

Instantly share code, notes, and snippets.

@emilstahl
Created November 13, 2013 23:52
Show Gist options
  • Save emilstahl/7458694 to your computer and use it in GitHub Desktop.
Save emilstahl/7458694 to your computer and use it in GitHub Desktop.
Center an image vertically and horizontally in a container URL: http://www.brunildo.org/test/img_center.html Thanks to Brunildo.org for this: http://www.brunildo.org/test/img_center.htmll
<style type="text/css">
.wraptocenter {
display: table-cell;
text-align: center;
vertical-align: middle;
width: ...;
height: ...;
}
.wraptocenter * {
vertical-align: middle;
}
/*\*//*/
.wraptocenter {
display: block;
}
.wraptocenter span {
display: inline-block;
height: 100%;
width: 1px;
}
/**/
</style>
<!--[if lt IE 8]><style>
.wraptocenter span {
display: inline-block;
height: 100%;
}
</style><![endif]-->
<div class="wraptocenter"><span></span><img src="..." alt="..."></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment