- AMP:Building Accelerated Mobile Pages
- Ruadhan O'Donoghue
- 140字
- 2021-07-08 10:04:07
Using responsive images and srcset to deliver high quality images on all screen sizes
To achieve the second goal, we can use layout="responsive" again, so that the thumbnails will scale for larger screens. The HTML for each item in the list now looks like this:
<li>
<figure class="related-thumb">
<amp-img src="img/penguin.jpg" width="125" height="75" layout="responsive"></amp-img>
<figcaption>
If a penguin can find a soul mate, I'm sure I can too
<span class="author">Rebekah Crane</span>
</figcaption>
</figure>
</li>

Thumbnails in 2x2 grid and with layout="responsive" scaling up on a larger screen (tablet device in portrait orientation)
There is a problem with this solution, however. It's the same problem that we had earlier when our main feature image was scaled up on large screens: it became pixelated. The same thing will happen with our thumbnails. Thankfully, we can apply the same solution as before using srcset:
<amp-img src="penguin.jpg"
srcset="img/penguin-sm.jpg 125w,
img/penguin.jpg 640w"
width="125"
height="75"
layout="responsive"
</amp-img>
Now, on larger screens, the browser will automatically use the higher resolution image.
推薦閱讀
- 小創客玩轉圖形化編程
- Java高并發核心編程(卷2):多線程、鎖、JMM、JUC、高并發設計模式
- Reactive Programming with Swift
- C和C++安全編碼(原書第2版)
- Learning SAP Analytics Cloud
- Mastering matplotlib
- HTML5+CSS3 Web前端開發技術(第2版)
- IBM Cognos Business Intelligence 10.1 Dashboarding cookbook
- C++20高級編程
- QGIS Python Programming Cookbook(Second Edition)
- 新印象:解構UI界面設計
- Java7程序設計入門經典
- Java多線程并發體系實戰(微課視頻版)
- Mastering Swift 4(Fourth Edition)
- Access 2010數據庫教程(微課版)