【发布时间】:2016-07-09 00:41:29
【问题描述】:
我试图在包装器中包含图像,保持其纵横比。然而,图像伸展。 以下是我遇到的问题的示例 amp html。
<style>
.image-wrapper {
width: 150px;
height: 150px;
background: teal;
}
.image-wrapper img {
height: auto;
width: auto;
max-width: 150px;
max-height: 150px;
}
</style>
<div class="image-wrapper">
<amp-img
src="http://fyogi.com/public/images/products/mobiles/lg-google-nexus-5x-mqqci.c1.w150.jpg"
layout="responsive"
width="150"
height="150">
</amp-img>
</div>
渲染页面后,这是amp版本
<div class="image-wrapper">
<amp-img src="http://fyogi.com/public/images/products/mobiles/lg-google-nexus-5x-mqqci.c1.w150.jpg" layout="responsive" width="130" height="130" class="-amp-element -amp-layout-responsive -amp-layout-size-defined -amp-layout" id="AMP_1"><i-amp-sizer style="display: block; padding-top: 100%;"></i-amp-sizer>
<img amp-img-id="AMP_1" class="-amp-fill-content -amp-replaced-content" width="130" height="130" src="http://fyogi.com/public/images/products/mobiles/lg-google-nexus-5x-mqqci.c1.w150.jpg"></amp-img>
</div>
下面的样式是amp在渲染后添加的,导致拉伸图像,将min-width:100%添加到img元素
.-amp-fill-content {
display: block;
min-width: 100%;
max-width: 100%;
height: 100%;
margin: auto;
}
现在我可以通过添加 min-width: auto 的解决方法修复此问题,但它会破坏使用 amp html 布局响应和文档的目的,明确表示对于 layout responsive
元素的大小调整为其容器元素的宽度,并调整其高度的大小自动调整为由宽度和高度属性给出的纵横比。
问题陈述
我有未知尺寸的图像源,但小于 150X150 像素,理想情况下,宽度或高度均为 150 像素。我需要将此图像在固定 150X150 分区的中心/中间(水平和垂直)对齐,如果可能的话,我希望将所有尺寸保持在 em/rem 中。
【问题讨论】:
-
检查此stackoverflow.com/questions/33878352/… 可能会有所帮助。
-
已经看过了,帮不上忙:(