假设我有 container.a 并且它有一些高度(以像素为单位),假设我在 container.a 中有另一个 container.b,它是 container.a 的 80%,现在说我想要适合具有一定高度的图像pixels into container.b,如何让图像的高度为container.b的高度,然后使用CSS保持宽度纵横比?
<div class="container.a">
<div class="container.b">
<img class="image.a" src="my_image.png" />
</div>
</div>
.container.a { width: 200px; height: 300px; }
.container.b { width: 80%; height: 80%; }
.image.a { ? }
最佳答案
给图片100%的宽度
.image.a{width:100%;}
关于css - 通过将图像高度设置为容器高度,使图像适合其容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16037566/