在給網頁加背景圖時會遇到:圖片過大,只能顯示出部分,不能完整的顯示出來,實現不了設計的效果,怎么辦?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>無標題文檔</title> <style type="text/css"> body{ background:url(images/hi-wifi-bg.jpg) no-repeat center center; background-size:100% 100%; } </style> </head> <body> <p style=" width:100px; height:1000px;background:#000; opacity:0.5;"> </p> </html> </body> </html>
background:url(images/hi-wifi-bg.jpg) no-repeat center center; background-size:100% 100%;
背景圖片的定位background-position設為center center(x,y)
background-size規定背景圖像的尺寸,默認值是auto,
語法
background-size: length|percentage|cover|contain;
在這些屬性中多試幾次