### 背景固定的滾動頁面布局:
#### 1、示例如下(可直接復制以下完整代碼):
* * * * *
~~~
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>背景固定的滾動效果</title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
body{
height: 100%;
}
.box{
height: 100%;
position: relative;
z-index: 1;
}
.fixed_bg{
position: relative;
height: 100vh;
min-height: 100%;
background-size: cover;//單獨設置屬性
background-repeat: no-repeat;//單獨設置屬性
background-position: center center;//單獨設置屬性
z-index: 1;//層級為1,要比沒有設置背景固定的層級低
background-attachment: fixed;//背景固定
}
.scrolling_bg{
position: relative;
height: 100vh;
min-height: 100%;
background: #b4d7a8;
z-index: 2;
}
.box1{
background-image: url(img/cd-background-1.jpg);//設置背景圖片
}
.box3{
background-image: url(img/cd-background-2.jpg);//設置背景圖片
}
.box5{
background-image: url(img/cd-background-3.jpg);//設置背景圖片
}
h2{
width: auto;
height: 50px;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: auto;
line-height: 50px;
font-size: 50px;
color: #0162AC;
text-align: center;
}
</style>
</head>
<body>
<div class="box">
<div class="fixed_bg box1">
<h2>歡迎進入背景固定頁面觀賞</h2>
</div>
<div class="scrolling_bg box2">
<h2>這是頁面第二屏</h2>
</div>
<div class="fixed_bg box3">
<h2>這是頁面第三屏</h2>
</div>
<div class="scrolling_bg box4">
<h2>這是頁面第四屏</h2>
</div>
<div class="fixed_bg box5">
<h2>這是頁面第五屏</h2>
</div>
</div>
</body>
</html>
~~~
#### 2、注意事項:
* * * * *
1. 使用:background-attachment: fixed;來設置背景固定;
2. 背景固定所在的div層級要比沒有設置背景固定的div的層級低;
3. 設置背景圖片時,只能使用:background-image: url();,不能使用:background: url(img/cd-background-3.jpg) no-repeat center center;,否則無效,其他屬性要單獨設置;
- 我的爛筆頭
- 1、常用功能方法整合
- 2、jQuery基本函數
- 3、在頁面中添加圖片
- 4、精度算法
- 5、圖片懶加載
- 6、彈窗拖拽功能
- 7、彈幕功能
- 8、鼠標滾動事件
- 9、獲取頁面相關屬性
- 10、彈窗的三種展現方式
- 11、輪播功能
- 12、獲取唯一標識
- 13、CSS樣式效果
- 14、任意兩點的動態連線
- 15、全新接口功能
- 16、適配兼容
- 17、無刷新頁面更改URL
- 18、定時器的那些事
- 19、關于iframe的常見問題
- 20、設置不同的時間
- 21、關于select-option
- 22、省市級聯
- 23、省市級聯數據
- 24、關于數據傳輸問題
- 25、問題分支
- 那些年我們一起走過的神坑
- 1、關于console的使用
- 2、關于數組
- 1、數組的賦值
- 2、數組的常用方法
- 3、關于移動端的bug
- 4、關于視頻的bug
- 5、那些坑坑洼洼
- 6、關于字符串
- 1、字符串的常用方法
- 頁面布局
- 1、背景固定的滾動頁面
- 心得
- Node.js
- 1、安裝環境
- ThinkPHP 5.1
- 1、訪問格式