문제

I want to display my image in full-width Gallery. The container is static:

#container{
    width:100%;
    height:400px;
}

<div id="container">
   <img src="myimage.jpg">
</div>

I have images of different dimensions, so I want display the image in full width without deformate this in height, but centering the image (in height way) to diplay it in the center.

도움이 되었습니까?

해결책

If you want to keep the same aspect ratio but your images are different dimensions your best solution would be as Patsy Issa is saying.

Use css

#myimage{
    background: url("myimage.jpg") no-repeat center center; 
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
    width:100%;
    height:400px;
}

And HTML

<div id="container">
    <div id="myimage"></div>
</div>

JSFiddle: http://jsfiddle.net/qBPy6/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top