【问题标题】:Images stretching in Flexbox on Firefox在 Firefox 上的 Flexbox 中拉伸图像
【发布时间】:2016-05-04 01:23:32
【问题描述】:

CSS3 flexbox 在 Safari 和 Chrome 上运行良好,但在 Firefox 上图像被拉伸。我该如何解决这个问题?

下面是代码示例:

body{
  padding: 30px;
}
.img-wrapper{
  display: -webkit-flex;
  display: flex;
  display:-moz-box
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: center;
  justify-content: center;
  height: 350px;
  background-color: #eee;
}
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>

<div class="row">
  <div class="col-xs-4">
    <div class="img-wrapper">
      <img class="img-responsive" src="https://www.googledrive.com/host/0B_o3I6x00l9PUFRRLWUtM0wzUG8" alt="">
    </div>
  </div>
  <div class="col-xs-4">
    <div class="img-wrapper">
      <img class="img-responsive" src="https://www.googledrive.com/host/0B_o3I6x00l9PMjJqSnd6UVU4OXc" alt="">
    </div>
  </div>
  <div class="col-xs-4">
    <div class="img-wrapper">
      <img class="img-responsive" src="https://www.googledrive.com/host/0B_o3I6x00l9PZjFIUy03UW9fOGM" alt="">
    </div>
  </div>
</div>

【问题讨论】:

标签: css firefox safari flexbox


【解决方案1】:

也许它现在可以正常工作remove display:-moz-box 你也没有关闭它。您无需使用它。 替换此 CSS 代码。它会起作用的。 https://jsfiddle.net/hamzanisar/w6na28km/

body{
      padding: 30px;
    }
      .img-wrapper{
  display:-webkit-flex;
  display:flex;
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: center;
  justify-content: center;
  height: 350px;
  background-color: #eee;
  position:relative;
}
.img-wrapper img{
   bottom: 0;
height: auto;
left: 0;
margin: auto;
max-height: 100%;
max-width: 100%;
position: absolute;
right: 0;
top: 0;
width: auto;}

【讨论】:

  • 感谢您的回复。但图像在 Firefox 上拉伸。
  • 我已经在 Firefox 上进行了测试,它工作正常。测试它让我知道仍然存在问题。
  • 是的!同样的问题是截图link
  • 好的我已经更新了代码检查这个:jsfiddle.net/w6na28km/1现在很好
  • 我只需将 max-width 和 max-height 设置为 100% 就可以了!
猜你喜欢
  • 2019-12-22
  • 2016-08-17
  • 2017-02-25
  • 1970-01-01
  • 2017-06-17
  • 2022-11-01
  • 2017-05-09
  • 2015-12-22
  • 2018-01-26
相关资源
最近更新 更多