【问题标题】:Why can't i maintain aspect ratio with max height value?为什么我不能保持最大高度值的纵横比?
【发布时间】:2016-06-05 14:37:48
【问题描述】:

我为我的纵向和横向图像使用了一个类。我所有的风景图像都具有相同的 1400x1000px 大小(700x500px 5K 视网膜证明)。而且我希望肖像图像的高度和宽度始终为 700 像素,并将其设置为自动,但它似乎不是这样工作的。为什么?

.size-m { /* project image portrait */
  max-height: 700px;
  width: auto;
 }

.size-xl { /* project image landscape */
 max-width: 700px;
 height: auto;
}

【问题讨论】:

    标签: css image height width aspect-ratio


    【解决方案1】:

    display: block 添加到您的课程中。这应该可以解决问题。

    【讨论】:

      【解决方案2】:

      我可能会误解,但这似乎在这些 jsfiddles 中工作正常:

      landscape

      img {
        max-width: 700px;
        height: auto;
      }
      

      portrait

      img {
        max-height: 700px;
        width: auto;
      }
      

      【讨论】:

      • 谢谢它与我的 css 布局有关,一个类会干扰。
      猜你喜欢
      • 2015-06-13
      • 2015-01-21
      • 2021-06-12
      • 2021-02-09
      • 1970-01-01
      • 2015-12-02
      • 2017-10-25
      • 2014-12-13
      相关资源
      最近更新 更多