- 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.
推薦閱讀
- JavaScript 從入門到項目實踐(超值版)
- 網頁設計與制作教程(HTML+CSS+JavaScript)(第2版)
- 軟件項目管理實用教程
- Learning Hunk
- Learning ArcGIS for Desktop
- Go語言編程
- C# Multithreaded and Parallel Programming
- 精通MySQL 8(視頻教學版)
- Python一行流:像專家一樣寫代碼
- Learning Grunt
- PHP動態(tài)網站開發(fā)實踐教程
- Mastering Python
- 精益軟件開發(fā)管理之道
- Dart:Scalable Application Development
- 算法訓練營:海量圖解+競賽刷題(入門篇)