The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › CSS › [Solved] Inline equivalent of background-position?
I have an inline image that I’m trying to horizontally/vertically center inside a div of a smaller size with overflow: hidden, how do I do that by targeting the img tag itself and not using “background-position” on the parent container itself?
Example
If you know the width/height of the image, then it’s pretty easy: http://codepen.io/senff/pen/tfgks
If you don’t know the image size, it will be a little trickier and you may have to use some Javascript.
That image is not really centered in Chrome, so you may still need prefixes:
http://codepen.io/senff/pen/Fworh
Sweet! Thanks Jacob!