【问题标题】:max-width versus max-height in Google ChromeGoogle Chrome 中的最大宽度与最大高度
【发布时间】:2012-11-26 02:00:15
【问题描述】:

我正在尝试根据容器高度仅使用 CSS 调整图像大小。这是代码和fiddle

<div id="first">
<img src="http://www.helpinghomelesscats.com/images/cat1.jpg" width=360 height=360>  
</div>​

#first {
    height: 100px;
}
img {
    max-height: 100%;
    width: auto !important;
}

在 Chrome 中无法设置最大高度。图像被展平。在 Firefox 和 IE 中看起来还可以。 但是,设置 max-width 在所有浏览器中都有效。

#first {
    width: 100px;
}
img {
    max-width: 100%;
    height: auto !important;
}

有人可以告诉我,如何获得最大高度的正确结果,这也适用于 Chrome 吗?

【问题讨论】:

    标签: css


    【解决方案1】:

    有趣的是,Chrome 似乎并没有用“auto”覆盖固定宽度,尽管 Inspector 这么说。

    最简单的解决方案是不指定图像的widthheight 属性。

    【讨论】:

      猜你喜欢
      • 2013-09-23
      • 1970-01-01
      • 2014-02-27
      • 2013-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-30
      • 1970-01-01
      相关资源
      最近更新 更多