CSS
响应式 Web 设计 - 图片
以下大图片和小图片将显示在不同设备上
源代码:
点击运行 »
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta charset="utf-8"> <style> /* For width smaller than 400px: */ body { background-repeat: no-repeat; background-image: url('/wp-content/uploads/2015/06/img_smallflower.jpg'); } /* For width 400px and larger: */ @media only screen and (min-width: 400px) { body { background-image: url('/wp-content/uploads/2015/06/img_flowers.jpg'); } } </style> </head> <body> <p style="margin-top:360px;">调整浏览器宽度,背景图片在小于 400 px 时将改变。</p> </body> </html>
运行结果:
点击运行 »