I'm trying to center an absolute positioned img inside a relative positioned div and the image is bigger than its parent(in a 767px window or lower). But the image does have a fixed width of 767px. What makes it hard for me is that parent div does not have a fixed width, it has a 100% width so I'd have to somehow generate the correct amount of pixels for the 'left' attribute on each resize but I don't know how. I tried setting percentages but with no succes when resizing.
I have been able to somewhat do it with javascript but I'd rather have a css solution since the javascript doesn't work consistently for me.
I need to be able to center the img when the parent div gets smaller than 767px and the img always remains 767px within the div and has a height of 257px.
Any help is appreciated!
html code:
<div class="item">
<img src="...">
</div>
css:
.item{
position:relative;
height:257px;
overflow:hidden;
}
.item img{
min-width:767px;
position:absolute;
}
min-width
on the image – do you want the image to be stretched to fill the whole container width, if the container is wider than 767px? – Bloemfontein