CSS: how to vertically and horizontally align an image?

后端 未结 7 951
青春惊慌失措
青春惊慌失措 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 12:51

    In case someone still needs this here's a way to do it with display table;

    .thumbnail { width:150px; height:150px; display: table; }
    
    .thumbnail img { max-width:150px; max-height:150px; }
    
    .thumbnailcontainer { display:table-cell; vertical-align: middle; text-align:center;}

提交回复
热议问题