html - 图像和文本并排在 div 中,想在调整大小时缩小图像

标签 html css reactjs responsive-design flexbox

我有一个 div,左边是图像,右边是一些文本。我正在使用 flexbox,这样当屏幕变窄时,文本会在图像下方弹出。

我希望在缩小屏幕时发生的不仅是文本变窄而且图像也缩小并保持其位置。取而代之的是文本缩小并且图像向下移动页面(保持相同大小)以保持居中。我怀疑这与 align-items: center 试图保持居中有关,但我删除了它然后图像只是拉伸(stretch)。

我该如何解决?

.bio {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
  flex-direction: row;
  width: 80%;
  margin: auto;
  margin-bottom: 30px;
  align-items: center;
}

.bio-text {
  flex: 200px;
}

.bio-text p {
  line-height: 25px;
  font-family: "Nunito sans", sans-serif;
}

.bio-h3-container {
  text-align: center;
}

.headshot {
  max-width: 100%;
  height: auto;
  margin-left: 40px;
  margin-right: 40px;
}
<div className="bio">
  <img className="headshot" src={Headshot} />
  <div className="bio-text">
    <div className="bio-h3-container">
      <h3>Bio</h3>
    </div>
    <p>...bunch of text here...</p>
  </div>
</div>

最佳答案

您可以使用内联样式将图像设为 background-image,即 style={{backgroundImage: Headshot}}

然后把css类background-size:contain放在上面。这应该可以使图像调整到 div

关于html - 图像和文本并排在 div 中,想在调整大小时缩小图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49326522/

相关文章:

reactjs - 如何使用 React 和 TypeScript 创建通用箭头函数

javascript - 如何在 React 渲染函数中从 JSON 对象获取值?

javascript - transitionConfig 在 native react 中不起作用

html - 是否可以在滚动时保持 div 位置固定但保持与容器对齐?

javascript - 动画表格行滑出或淡入?

html - 更改页面宽度颜色背景

css - 使用 Material-UI 将 Logo 与中心对齐

jquery - 使用 jquery blivesta animsition 添加页面转换而不是链接转换

html - 如何将一个div置于另一个div中

html - 从底部到顶部堆叠 Div