简体   繁体   English

居中动态高度/宽度图像固定为高度/宽度div

[英]Center dynamic height/width Image to fixed height/width div

I've problem with centering dynamic image to fixed size div. 我将动态图片居中固定大小div时遇到问题。 So, the main idea is that image knows how to scale itself whether it is panoramic image or portrait image. 因此,主要思想是图像知道如何缩放自身,无论是全景图像还是肖像图像。 The div, I'm aligning to, is close to 16:9 (300x170). 我要对齐的div接近16:9(300x170)。 Any ideas? 有任何想法吗?

try this - DEMO 试试这个- 演示

div {
    height: 170px;
    width: 300px;
    border: solid;
    line-height: 170px;
    text-align: center;
}

div img {
    display: inline-block;
    max-width: 300px;
    max-height: 170px;
    vertical-align: middle;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM