码迷,mamicode.com
首页 > 其他好文 > 详细

响应式图片

时间:2017-08-20 20:02:08      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:表示   init   cal   com   code   logs   响应式   name   ble   

<picture>元素与<source>元素

例如需要分别在小于640px 大于640px 小于960px 和 大于960px的3个区域内使用small.jpg medium.jpg large.jpg可以这么编码

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4     <meta charset="UTF-8">
 5     <meta name="viewport" content="width=device-width, initial-scale=1.0">
 6     <meta http-equiv="X-UA-Compatible" content="ie=edge">
 7     <title>响应式图片</title>
 8 </head>
 9 <body>
10     <picture>
11         <source media="(max-width:640px)" srcset="small@2x.jpg 2x, small.jpg 1x"/>
12         <source media="(max-width:960px)" srcset="medium@2x.jpg 2x, medium.jpg 1x"/>
13         <source srcset="large@2x.jpg 2x, large.jpg 1x"/>
14         <img src="small.jpg" alt="">
15     </picture>
16 </body>
17 </html>

分析

max-width:640px  表示页面不足640px 
small@2x.jpg 2x, small.jpg 1x  告诉浏览器该来源为同一素材提供了两种清晰度的版本

响应式图片

标签:表示   init   cal   com   code   logs   响应式   name   ble   

原文地址:http://www.cnblogs.com/Mr-W/p/7400731.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!