CSS: how to vertically and horizontally align an image?

后端 未结 7 905
青春惊慌失措
青春惊慌失措 2020-12-31 12:27

My page has space for an image that can be, say, a maximum 100x100 image. Users can upload any image dimension and the web application will resize it, maintaining aspect rat

7条回答
  •  孤城傲影
    2020-12-31 13:10

    You could try this:

    .image_container {
        display:table-cell;
        overflow:hidden;
        text-align:center;
        vertical-align:middle;
    }
    .image_container img {
        vertical-align:baseline;
    }
    

    Not 100% sure on browser compatibility, but should get you started in the right direction. Example: http://jsfiddle.net/fJtwX/1/

提交回复
热议问题