Skip to content

Instantly share code, notes, and snippets.

@dziudek
Created May 24, 2012 07:59
Show Gist options
  • Save dziudek/2780111 to your computer and use it in GitHub Desktop.
Save dziudek/2780111 to your computer and use it in GitHub Desktop.
Image always centered vertically and horizontally
/**
* Image always centered vertically and horizontally
*/
div#main {
border: 2px solid #aaa;
display: table;
width: 100%;
height: 300px;
}
div#main > div {
display: table-cell;
vertical-align: middle;
}
div > img {
display: block;
margin: 0 auto;
max-width: 100%;
height: auto;
}
<div id="main">
<div>
<img src="http://placekitten.com/600/260" alt="Kitty 200x200 ;)" />
</div>
</div>
{"view":"split","fontsize":"100","seethrough":"","prefixfree":"1","page":"css"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment