html - 与 Firefox 相比,图像在 Chrome 中未正确调整大小

标签 html css image google-chrome firefox

我有一个显示图像的 html 页面。 当图像大于浏览器的窗口时,图像会调整大小(保持相同的比例)以适应 Firefox 的窗口。 但是使用 Chrome,图像被压缩了

这是html代码:

<div class="container">
  <div class="auto">
    <img class="full-width" src="http://laurent.delrocq.free.fr/test/img-1.jpg" />
    <div class="absolute">
        <img src="http://laurent.delrocq.free.fr/test/left.png" alt="#" class="left">
        <img src="http://laurent.delrocq.free.fr/test/right.png" alt="#" class="right">
    </div>
  </div>
</div>

和CSS:

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

.container {
  text-align: center;
}
.auto {
        width:auto;
        height:auto;
        position:relative;
        display:inline-block;
    }

    .absolute {
        position:absolute;
        top:0;
        left:0;
        height:100%;
        width:100%;
        z-index:2;
    }

    .left {
        position:absolute;
        top:50%;
        left:15px;
        transform: translateY(-50%);
    }

    .right {
        position:absolute;
        top:50%;
        right:15px;
        transform: translateY(-50%);
    }

  .full-width {
    width:auto;
    max-width:100%;
    max-height: 100vh;
    height:100%;
  }

如何更改代码以使其在 Firefox 和 Chrome 上都能正常工作(调整大小)?

最佳答案

伙计,这是您要搜索的解决方案: https://jsfiddle.net/d5z3fnjh/1/

检查“.container”、“.auto”和“.full-width”的宽度和高度值:

.full-width {
  width:100%;
}
.container {
  text-align: center;
  width: 100vw;
}
.auto {
  width:100%;
  position:relative;
  display:inline-block;
}

更新: 这是JS的解决方案: https://jsfiddle.net/d5z3fnjh/4/

关于html - 与 Firefox 相比,图像在 Chrome 中未正确调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44862776/

相关文章:

html - 在 R 中将 HTML/CSS 转换为图像(png 或任何无损格式)

html - 异步加载图像

android - 如何在android中的 ImageView 上设置图像路径

html - 将鼠标悬停在另一个 DIV 的子 CSS 上时显示 DIV

javascript - 在以 POST(而不是 GET)方式发送请求后,如何将对象作为 html 页面插入到来自后端的 html 元素中?

html - 如何将一个垂直图像与 block 中的另外 2 个垂直图像对齐

css - 涉及 thead 和 div 的重叠元素

javascript - 如何在移动设备中并排定位两个绝对定位的 div,?

javascript - 如何使用 twitter bootstrap 3 使等待图标出现在我的页面中间?

ios - CollectionView 不使用 DKImagePickerController 重新加载