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;
}


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

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

相关文章:

css - 解决 npm 模块依赖

css - 自定义登录页面CSS样式

html - 如何在链接后放置图片?

C++图像过滤算法

javascript - jquery下拉菜单解释

html - 如何在同一div内对齐这三张卡?

html - 绝对和相对

html - 无序列表中 img 下方的奇怪空格

html - Syncfusion TreeView控件CSS问题

html - 标题按钮是正方形而不是圆形