html - 火狐漏洞 : image does not scale down?

标签 html css firefox flexbox

这是 firefox 中的错误吗?

CSS,

html, body {
    height: 100%;
    margin: 0;
    padding: 0 0;
    /*border: 4px solid black;*/
}

.container-fluid {
    height: 100%;
    width: 100%;
    display: table;
    padding-right: 0;
    padding-left: 0;
    /*border: 4px solid blue;*/
}

.row-fluid {
    height: 100%;
    width: 100%;
    display: table-cell;
    vertical-align: middle;
    background-color:#990000;
    /*border: 4px solid red;*/
}

.img-container {
    height: 100vh;
    width: 100%;
    display: flex;
    align-items: center;
}

.img-container img{
    max-width:100%;
    max-height:100%;
    margin-left: auto;
    margin-right: auto;
}

HTML,

  <div class="container-fluid">
    <div class="row-fluid">
        <div class="img-container">
            <!-- <img src="http://placehold.it/400x450"> -->
            <img src="http://placehold.it/2000x450">
            <!-- <img src="http://placehold.it/400x480"> -->
        </div>
    </div>
</div>

Chrome ,

enter image description here

大图像将按比例缩小以适应我想要的屏幕宽度。

火狐

enter image description here

图像缩小以适合屏幕。

有什么办法可以解决这个问题吗?

编辑:

@-moz-document url-prefix() {
    .img-container img {
        width: 100%;
        max-width: -moz-max-content;
    }
}

enter image description here

最佳答案

由于您已经在布局中使用 CSS 表格,所以我建议采用这种不使用 flexbox 的方法。根据我的测试,它在 Chrome 和 Firefox 上运行良好。我在 img 周围添加了一个 div

jsFiddle

body { margin:0; }

.img-container {
  display: table;
  table-layout: fixed; /*required for responsive width in Firefox*/
  width: 100%; /*required for fixed table layout*/
}
.img-container .image {
  display: table-cell;
  text-align: center;
  vertical-align: middle;
  height: 100vh; /*required for responsive height*/
}
.img-container .image img {
  max-width: 100%;
  max-height: 100%;
  vertical-align: middle; /*remove whitespace*/
}
<div class="img-container">
  <div class="image">
    <img src="http://placehold.it/400x300">
    <!-- <img src="http://placehold.it/2000x450"> -->
    <!-- <img src="http://placehold.it/400x480"> -->
  </div>
</div>

或者,您可以使用伪元素 :before:after + 垂直对齐的内联 block 。无需更改标记。

jsFiddle

body { margin:0; }

.img-container {
  width: 100vw; /*required for responsive width in Firefox*/
  height: 100vh;
  text-align: center;
  font-size: 0; /*remove whitespace*/
}
.img-container:after {
  content: "";
  display: inline-block;
  height: 100%;
  vertical-align: middle;
}
.img-container img {
  max-width: 100%;
  max-height: 100%;
  vertical-align: middle;
}
<div class="img-container">
  <img src="http://placehold.it/400x300">
  <!-- <img src="http://placehold.it/2000x450"> -->
  <!-- <img src="http://placehold.it/400x480"> -->
</div>

关于html - 火狐漏洞 : image does not scale down?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35354248/

相关文章:

javascript - 周突出显示在鼠标悬停时无法正常工作

html - 使用 CSS 垂直对齐

javascript - 使用 Highcharts.js 的圆边仪表

javascript - 如何设置/检测页面中浏览器 native 搜索生成的突出显示框

javascript - 检测国外网站参数变化

html - 导航栏包装器 HTML

javascript - 当浏览器移动到不同页面时显示加载图形

HTML 和 CSS 不起作用?

css - 更改滚动条高度

javascript - window.content.mozInnerScreenY 值在 Firefox 33.1 中不起作用