1. 背景 background: red url(img/cat.gif) repeat-x fixed;瀏覽器
2. 背景顏色 background-color: red;url
3. 背景圖片 background-image: url(img/cat.gif);spa
4. 背景圖片重複方式 code
.nav{ width: 990px; height: 32px; margin: 10px auto; background: #bfc url(img/bg.gif) repeat-x; }
截取背景 y 縱向一像素,而後「圖片-裁剪-存儲爲Web格式」,選擇格式,選大小合適的。blog
5. 一張圖片在元素內顯示位置圖片
background-position: 0% 0%; 默認值,從左上角開始顯示it
(x水平,y垂直)io
(1)class
x水平: 可選 left,right,center;bfc
y垂直: 可選 top,bottom,center;
注意:若是隻寫一個值,另外一個值默認爲center。
(2)
以元素的左上角爲原點,設置(100px,100px)
若是指定負值,則向反方向偏移。
6. 圖片 是否 隨頁面其他滾動background-attachment
缺點:
通常咱們設置窗口固定背景時,都設置給body。
由於若是設置給其餘元素,圖片會固定,元素不會固定。。。當元素不存在於視覺中,圖片就會顯示不全或者消失。。。