Amp html 如何使用响应式布局将amp img居中

Amp html 如何使用响应式布局将amp img居中,amp-html,Amp Html,以下代码不起作用。如果布局是固定的,If将起作用 <div style="text-align:center;"> <amp-img style="max-width: 640px;" width="640" height="480" layout="responsive" src="~/Content/images/foo.JPG" /> </div> 请注意style=“max width:640px;”用于防止此图像在窗口足够宽时填充宽度

以下代码不起作用。如果布局是固定的,If将起作用

<div style="text-align:center;">
    <amp-img style="max-width: 640px;"  width="640" height="480" layout="responsive" src="~/Content/images/foo.JPG" />
</div>

请注意style=“max width:640px;”用于防止此图像在窗口足够宽时填充宽度


任何提示都将不胜感激

您将图像包装在
div
中,这是一个好的开始。我不确定你的页面是如何设置的,但是对
div
应用0 auto的边距对我来说很有效

页边距:0自动以及为什么它可以或不可以用于居中

div.img-wrapper{
最大宽度:640px;
保证金:0自动;
}


如果你想玩它。

你的图像被包装在
div
中,这是一个好的开始。我不确定你的页面是如何设置的,但是对
div
应用0 auto的边距对我来说很有效

页边距:0自动以及为什么它可以或不可以用于居中

div.img-wrapper{
最大宽度:640px;
保证金:0自动;
}


如果你想玩它。

使用@Craig Scott方法和想法。我只在编写AMP图像代码以使图像居中时成功,如下所示

<div class="img-wrapper">
<amp-img src="https://jomutech.com/dispJomutechIcon.png height="50" width="250" layout="responsive" alt="Logo">
</amp-img>
</div>

<style amp-custom>
  div.img-wrapper {
    text-align: center;
  }
</style>


使用@Craig Scott方法和想法。我只在编写AMP图像代码以使图像居中时成功,如下所示

<div class="img-wrapper">
<amp-img src="https://jomutech.com/dispJomutechIcon.png height="50" width="250" layout="responsive" alt="Logo">
</amp-img>
</div>

<style amp-custom>
  div.img-wrapper {
    text-align: center;
  }
</style>


它起作用了。谢谢。我不需要设置最大宽度的放大器img与您的答案。它的工作。谢谢。我不需要设置最大宽度为放大器img与您的答案。