陪你做好前端设计!
源代码:
点击运行
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta charset="utf-8"> <title>素材8网教程(study.sucai8.cn)</title> <style> /* For width smaller than 400px: */ body { background-repeat: no-repeat; background-image: url('/images/img_smallflower.jpg'); } /* For width 400px and larger: */ @media only screen and (min-width: 400px) { body { background-image: url('/images/img_flowers.jpg'); } } </style> </head> <body> <p style="margin-top:360px;">调整浏览器宽度,背景图片在小于 400 px 时将改变。</p> </body> </html>
运行结果