Created
January 9, 2014 12:02
-
-
Save bmihelac/8333073 to your computer and use it in GitHub Desktop.
less mixin to center responsive image in fixed size element
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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