官术网_书友最值得收藏!

Your first AMP component - <amp-img>

The next validation error message is interesting:

The tag 'img' may only appear as a descendant of tag 'noscript'. Did you mean 'amp-img'?

This error deserves special attention: it's the first error that's complaining about what looks to be standard use of an HTML tag. It's basically telling us that the HTML <img> tag is not permitted in AMP, and it's suggesting an alternative <amp-img>.

Let's try to swap in <amp-img> in place of our <img> tag. Copy this line in instead:

<amp-img src="https://theampbook.com/ch2/lightning.jpg"></amp-img>

Note the closing </amp-img> tag. The HTML img tag is a void tag, which means that it doesn't need to be explicitly closed. However, the same does not hold for amp-img; so you must close it explicitly. Hit reload and check the developer console.

So that didn't work out so well: the image isn't displaying and the validator is reporting the following messages:

The implied layout 'CONTAINER' is not supported by tag 'amp-img'.
The mandatory attribute 'height' is missing in tag 'amp-img'.

The first error is complaining about layout, and the second is about a missing height attribute. Let's specify both the width and height attributes (if we omit width we'll see an error about that the next time we validate):

<amp-img src="https://theampbook.com/ch2/lightning.jpg"
width="768"
height="305"
>
</amp-img>
You must always specify width, and height for amp-img tags.

That fixed one of the errors, but we still need to deal with the layout error. Add the attribute layout="responsive" to the amp-img tag, so it now looks like this:

<amp-img src="https://theampbook.com/ch2/lightning.jpg"  
width="768"
height="305"
layout="responsive" >
</amp-img>

When you reload the page, you should now be able to see the image, and the validation errors should be gone.

主站蜘蛛池模板: 柘荣县| 前郭尔| 靖江市| 错那县| 呼和浩特市| 集安市| 东乡| 资中县| 茶陵县| 鸡西市| 稷山县| 双柏县| 满城县| 淮南市| 罗江县| 怀来县| 漳州市| 高州市| 晋中市| 白山市| 新巴尔虎左旗| 广宁县| 嵩明县| 马关县| 隆子县| 九龙坡区| 南木林县| 乌拉特后旗| 昌乐县| 罗定市| 彭山县| 合川市| 菏泽市| 北安市| 凉山| 汉沽区| 彩票| 鲜城| 黔西县| 桓台县| 囊谦县|