DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> CSS入門知識 >> DIV十CSS布局 >> 布局實例
用 CSS3 多背景定位打造滾動展示效果
編輯:布局實例     

透過 CSS3 的 background 定位屬性,可以讓多張背景圖在滾動時保持固定,營造出如畫卷般逐一展開的視覺效果。核心關鍵是 background 中的 fixed 關鍵字。

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>css3實現多背景展示</title>
</head>
<body>
<div style="height:5400px;">
  <div style="background:url(https://zcimg.zcool.com.cn/zcimg/m_fff653c539e10000015c06f796e0.jpg) no-repeat center center fixed;height:880px;margin-bottom:10px;"></div>
  <div style="background:url(https://zcimg.zcool.com.cn/zcimg/m_dfff53c539e40000015c06f6ff04.jpg) no-repeat center center fixed;height:880px;margin-bottom:10px;"></div>
  <div style="background:url(https://zcimg.zcool.com.cn/zcimg/m_0b3d53ce00b100000174d030a1fd.jpg) no-repeat center center fixed;height:880px;margin-bottom:10px;"></div>
  <div style="background:url(https://zcimg.zcool.com.cn/zcimg/m_c24d53ce007300000174d0debb3e.jpg) no-repeat center center fixed;height:880px;margin-bottom:10px;"></div>
  <div style="background:url(https://zcimg.zcool.com.cn/zcimg/m_606453ce006500000174d00396f9.jpg) no-repeat center center fixed;height:880px;margin-bottom:10px;"></div>
  <div style="background:url(https://zcimg.zcool.com.cn/zcimg/m_71fe53ce005e00000174d0000ac0.jpg) no-repeat center center fixed;height:880px;margin-bottom:10px;"></div>
</div>
</body>
</html>

每個 DIV 設定固定的高度(如 880px)並垂直排列,背景則採 no-repeat center center fixed,讓圖片始終固定於視窗中央。當使用者向下滾動時,一張張背景便依次入場,形成流暢的沉浸體驗。這種技法特別適合用於產品展示或作品集頁面。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved