<分区>
我在制作 <img>
时遇到问题在 flex parent 内部灵活。图像开始超出父级尺寸。我想给 parent 留下 display: flex;
并限制图像跨越父级的尺寸。
.full
{
width: 400px;
height: 200px;
background-color: blue;
display: flex;
flex-direction: row;
justify-content: flex-start;
}
.half
{
width: 50%;
background-color: red;
padding: 20px;
}
img
{
width: auto;
height: auto;
max-width: 100%;
max-height: 100%;
}
<div class="full">
<div class="half">
<h1>title</h1>
<img src="http://placehold.it/90x200">
</div>
</div>
您能否解释并提供一些有用的链接来解释所显示的行为及其可能的解决方案?
我同时使用 Firefox 和 Chrome 来查看。问题在两种浏览器中都存在。
这个问题似乎与 this question 重复