CSS 图像高度限制为父级 div 高度。父 div 宽度和高度以百分比指定*** [重复]

2024-02-22

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

如果图像宽度/高度 > 父级宽度/高度,我希望图像跨越父级。 如果图像宽度/高度

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

#top{
    height:10%;
}

#middle{
    height:80%;
}

#bottom{
    height:10%;
}

img{
    width: how much?
    height: how much?
}
<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>

height: 100%;
width: auto;

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

CSS 图像高度限制为父级 div 高度。父 div 宽度和高度以百分比指定*** [重复] 的相关文章

随机推荐