第一種:使用background-size:cover;
background-size屬性指定背景圖片大小。
注意瀏覽器兼容。
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>背景圖片自適應填充整個頁面</title> </head> <style> body{background: url(u=3577773561,2706257243&fm=26&gp=0.jpg) no-repeat;background-size:cover;} </style> <body> </body> </html>
=============================================================================
第二種:background-size:100% 100%;background-attachment:fixed;
background-size屬性指定背景圖片大小。
background-attachment設置背景圖像是否固定或者隨着頁面的其余部分滾動。
注意瀏覽器兼容。
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>背景圖片自適應填充整個頁面</title> </head> <style> body{background: url(u=3577773561,2706257243&fm=26&gp=0.jpg) no-repeat;background-size:100% 100%;background-attachment:fixed;} </style> <body> </body> </html>