I have a div with width:100px
and height:100px
(say)
Inside that, there is just an image, for which height is always fixed to 100px
.
I want to make the image horizontally center.
Here there are 3 cases:
- image's width is equal to div's width, no issues
- image's width is less than div's width, I can use
margin: auto
here
- image's width is more than div's width
I want the center part of the image to be visible inside the div.
means, if image's width is 120px
and as div's width is 100px
and overflow:hidden
I want image's 10th px to 110th px to be visible (so, the left: 10px
and right: 10px
of image are hidden under the div )
Is this possible through some CSS property?
(I dont know the width of image which is loading! so I want it to be dynamic.
Also want to avoid javascript side calculations to find the extra amount of width and giving margin-left:
-ve value bla bla.. )
Also, I can't give the image as background-image
for the div!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…