- AMP:Building Accelerated Mobile Pages
- Ruadhan O'Donoghue
- 151字
- 2021-07-08 10:04:06
Using the heights and sizes attributes
The heights and sizes attributes allow us to further tweak the display of our responsive images. The sizes attribute lets us use a media query to define how wide an image should be displayed, depending on the size of the user's viewport. Take the following code, for example:
sizes="(min-width: 640px) 50vw, 100vw"
This means that for screen sizes of 640 pixels and wider (min-width: 640px), the image should take up 50 percent of the viewport width (50vw). For all other screen sizes--that is--those less than 640 pixels, display the image at 100 percent of the viewport width: (100vw).
The heights attribute achieves a similar effect, but unlike sizes, it applies to the height of the image instead of the width, for example:
heights="(min-width:500px) 200px, 80%"
When the heights or sizes attribute is specified along with width and height, the layout defaults to responsive.
推薦閱讀
- Getting Started with Citrix XenApp? 7.6
- Java程序設計實戰教程
- Getting Started with React
- 精通搜索分析
- Full-Stack Vue.js 2 and Laravel 5
- Linux命令行與shell腳本編程大全(第4版)
- JavaScript:Moving to ES2015
- Web Development with MongoDB and Node(Third Edition)
- Node學習指南(第2版)
- Advanced UFT 12 for Test Engineers Cookbook
- 單片機原理及應用技術
- Greenplum構建實時數據倉庫實踐
- 軟件測試(慕課版)
- 數據結構與算法詳解
- Manage Your SAP Projects with SAP Activate