How can I center an img
in a parent div
tag which is set to overflow: hidden
. That is, what I want is to clip the image but clip on both the left/right so the middle of the image is shown.
<div class='wrapper'>
<img/>
</div>
Then styles something like:
.wrapper {
position: absolute;
/* position details here */
overflow: hidden;
}
.wrapper img {
height: 100%;
margin-left: -??; //what here?
}
-50%
would be the width of the parent, but I want the width of the img itself.
Firefox supported CSS is acceptable.
Hi please check example
its solve your problem
HTML
CSS
http://codepen.io/gcyrillus/pen/BdtEj
use text-align , line-height , vertical-align and negative margin. img virtually reduced to zero, will center itself.
For horizontal only :
Try to add
to ".wrapper img"