图像在弹性框 CSS 中不会缩小



当我在"main-intro"容器,文本和图像的宽度不相等。"main-intro"容器还具有超过父容器的宽度。我很困惑,是不是flexx应该自动应用相等的宽度到子元素?

"

<body>
<div class= "container">
<div class="main-intro">
<div class="intro">
<h1>We design and build better chairs, for a better life</h1>
<p>In a small shop in the heart of Lisbon, we spend our
days restlessly perfecting the chair. The result is a
perfect blend of beauty and comfort, that will have a lasting
impact on your health.
</p>
<a href="#">Shop chairs</a>
</div>
<img src="hero.jpg">
</div>

"

"

*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container{
width: 960px;
margin-right: auto;
margin-left: auto;
}
img{
width: 100%;
}
.main-intro{
display: flex;
}

"

你把整个页面变成了一个伸缩框,所以代码是正确的,只要在你想添加图像的地方添加flex .