CSS3移动端页面一张背景平铺
HTML CSS3 实现背景图片平铺整个屏幕(适用于移动端)
重要知识点:
background-repeat: no-repeat; //不重复
background-size: 100% 100%; // 满屏
.con{ background-image: url("./images/bgimg.png"); background-repeat: no-repeat; //不重复 background-size: 100% 100%; // 满屏 }
例如:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> *{ margin: 0; padding: 0; } html,body{ width: 100vw; height: 100vh; } body{ width: 100%; overflow-x: hidden; background: url("images/bg.jpg") no-repeat; background-size:100% 100%; /* background-attachment:fixed; */ } img{ vertical-align: middle; max-width: 100%; } </style> </head> <body> </body> </html>
效果如下所示:
还没有留言,还不快点抢沙发?