Skip to content

Instantly share code, notes, and snippets.

@pistatium
Created October 22, 2015 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pistatium/fcc1066dce29732d38bb to your computer and use it in GitHub Desktop.
Save pistatium/fcc1066dce29732d38bb to your computer and use it in GitHub Desktop.
responsive image
.box1 {
width: 100px;
height: 200px;
}
.box2 {
width: 300px;
height: 500px;
}
div {
position: relative;
background-color: #000;
margin-bottom: 30px;
}
div img {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: auto;
width: auto;
max-width: 100%;
height: auto;
max-height: 100%;
}
<div class="box1"><img src="http://placehold.it/300x250" alt="" /></div>
<div class="box2"><img src="http://placehold.it/300x250" alt="" /></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment