Skip to content

Instantly share code, notes, and snippets.

@bmihelac
Created January 9, 2014 12:02
Show Gist options
  • Save bmihelac/8333073 to your computer and use it in GitHub Desktop.
Save bmihelac/8333073 to your computer and use it in GitHub Desktop.
less mixin to center responsive image in fixed size element
// center responsive image in fixed size element
.center-image(@width, @height) {
position: relative;
// make parent element width/height divisible by 2
width: floor((@width + 0.5) / 2) * 2;
height: floor((@height + 0.5) / 2) * 2;
img {
display: block;
max-width: 100%;
max-height: 100%;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment