html讓背景圖片自適應填充整個頁面的兩種方法


第一種:使用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>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM