CSS图像高度限制为父div高度.父div宽度和高度以百分比指定***

Adi*_*ula 3 html css image css3

如何将图像的高度限制为其高度以百分比指定的父容器?

如果图像宽度/高度>父宽度/高度,我希望图像跨越父对象.如果图像宽度/高度<父宽度/高度,则图像与父对齐.在任何情况下,我都不希望图像被拉伸[垂直/水平.]

html, body{
    width:100%;
    height:100%;
}

#top{
    height:10%;
}

#middle{
    height:80%;
}

#bottom{
    height:10%;
}

img{
    width: how much?
    height: how much?
}
Run Code Online (Sandbox Code Playgroud)

<html>
    <body>
        <div id="top">I am top</div>
        <div id="middle">
            <img src="/images/abc.jpg" />
        </div>
        <div id="bottom">I am bottom</div>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

bjb*_*568 15

height: 100%;
width: auto;
Run Code Online (Sandbox Code Playgroud)

只需将图像高度定义为百分比,自动宽度将保持比例.