【问题标题】:Aspect ratio of box with image and text / Img goes narrow to height [duplicate]带有图像和文本的框的纵横比/ Img变窄到高度[重复]
【发布时间】:2026-02-14 15:15:02
【问题描述】:

我的网站上有一些带有图像的框,每当我将浏览器缩小到更小的宽度,或在移动设备上显示时,图像(圆圈)会改变纵横比并且不再是圆圈......只是窄椭圆形。

HTML/CSS + 下面的截图示例。

.imgElectroCont {
  display: flex;
  position: absolute;
  align-items: center;
  left: 0;
  margin: 40px 0 0 50px;
  opacity: 1;
  background-color:yellow;
}


.imgElectro {
  width: 150px;
  height: 150px;
  border-radius: 100%;
  border: 5px solid #fff;
  background-color:blue;
  background-repeat: no-repeat;
  background-size: contain;
  box-shadow: 3px 3px 10px var(--colorGreyDark);
}
<div class="imgElectroCont">
  <div class="imgElectro"></div>
  <a href="">Some text here nex to image</a>
</div>

【问题讨论】:

  • 您可以在 vh 中设置 .imgElectro 的高度和宽度而不是 px 以获得所需的结果。

标签: html css aspect-ratio


【解决方案1】:

尝试给你的 .imgElectro 类 flex-shrink: 0;

【讨论】:

    最近更新 更多