- AMP:Building Accelerated Mobile Pages
- Ruadhan O'Donoghue
- 266字
- 2021-07-08 10:04:05
Using responsive layout
Responsive design is built directly into AMP, and is one of the most useful layouts offered by the layout attribute. We saw how to use amp-img with the responsive layout in our news article example from the last chapter:
<amp-img
src="img/feature.jpg"
width="768"
height="305"
layout="responsive" >
</amp-img>
Note that even though we are using the responsive layout, we still need to specify the width and height attributes. Shouldn't it just grow and shrink to fit the viewport? There are two reasons why the width and height attributes are needed:
- To calculate the aspect ratio of the image so that it is displayed correctly as it is resized.
- To calculate the page layout before anything is downloaded; this is required by AMP's static layout system.
Our example from the last chapter was a nice first attempt at a news article page, but there's a problem with it. It's not optimized for larger screens. When viewed on a larger screen, the main feature image becomes blocky and pixelated.
Why does this matter--isn't AMP just for small screens? Doesn't the M in AMP stand for Mobile? Well, no and yes (respectively), but it's more nuanced than this. Even in a mobile format, there is a multitude of different device screen sizes that must be accommodated; our AMP pages should look good on all of them. And there is also the idea of Canonical AMP pages: an approach to web publishing where AMP is used exclusively to build a website, for desktop and mobile. In both theses cases, responsive design helps to deal with the wide variety of viewport sizes that must be handled.
- Android應用程序開發與典型案例
- 零基礎玩轉區塊鏈
- FreeSWITCH 1.6 Cookbook
- Ray分布式機器學習:利用Ray進行大模型的數據處理、訓練、推理和部署
- Linux Device Drivers Development
- Spring Boot企業級項目開發實戰
- TMS320LF240x芯片原理、設計及應用
- 匯編語言編程基礎:基于LoongArch
- Odoo 10 Implementation Cookbook
- Microsoft 365 Certified Fundamentals MS-900 Exam Guide
- Python Programming for Arduino
- 3D Printing Designs:The Sun Puzzle
- C語言編程魔法書:基于C11標準
- 趣學數據結構
- Java程序設計(項目教學版)