如何在保持图像纵横比的同时阻止图像扩展我的Flex容器?

发布于 2025-02-01 15:20:23 字数 1130 浏览 1 评论 0原文

因此,无论我在将其放置在Flex容器中头顶右时尝试使用哪种图像,它都会在扭曲旁边的图像时扩展我的挠性容器,并扩展外部挠曲容器。我如何放置任何图像,同时也没有扩展图像所在的flex项目并扭曲其旁边的图像。我有Max-Height:100%;,但这没有帮助,我认为这是因为父容器没有高度集。这是可能的吗?

.head {
  grid-column: 2/3;
  grid-row: 1/2;
  border: solid 1px red;
  padding: 38px 40px;
}

.head-top {
  display: flex;
}

.head-search {
  width: 40%;
  border-radius: 15px;
  background-color: lightgrey;
}

.search-img {
  margin-right: 15px;
}

.head-top-right {
  display: flex;
  width: 45%;
  margin-left: 30px;
  border: solid black 1px;
}

.head-profile-pic {
  max-height: 100%;
}
<div class="head">
  <div class="head-top">
    <img src="pic/magnify.png" class="search-img">
    <input type="text" name="search" class="head-search" />
    <div class="head-top-right">
      <img src="pic/notifications.png">
      <img src="pic/earth.jpg" class="head-profile-pic">
    </div>
  </div>
</div>

So no matter what image I try to use when placing it in the flex container head-top-right, it expands my flex container while distorting the image next to it and also expands the outer flex container. How do I place any image while also not expanding the flex item the image is in and also distorting the images next to it. I have max-height:100%; but it's not helping and I assume that it's because the parent container does not have a height set. Is that a possibility?

.head {
  grid-column: 2/3;
  grid-row: 1/2;
  border: solid 1px red;
  padding: 38px 40px;
}

.head-top {
  display: flex;
}

.head-search {
  width: 40%;
  border-radius: 15px;
  background-color: lightgrey;
}

.search-img {
  margin-right: 15px;
}

.head-top-right {
  display: flex;
  width: 45%;
  margin-left: 30px;
  border: solid black 1px;
}

.head-profile-pic {
  max-height: 100%;
}
<div class="head">
  <div class="head-top">
    <img src="pic/magnify.png" class="search-img">
    <input type="text" name="search" class="head-search" />
    <div class="head-top-right">
      <img src="pic/notifications.png">
      <img src="pic/earth.jpg" class="head-profile-pic">
    </div>
  </div>
</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文