備注:默認的圖片背景,如果無設置,自動靠左上角對齊,如果設置其位置可以靠background-position定位(值可為像素或者百分比、center),如下
<style type="text/css">
body{
background-image: url('/i/eg_bg_03.gif');
//有no-repeat與repeat之分,默認的為repeat,自動重復xy軸自動鋪滿,或者:
//
background-attachment:fixed;
background-position: 30% 20%;//為x,y軸。 或者50px 100px; 或者:top、bottom、left、right 和 center
}
</style>
------------------------------上述屬性合并為一列----------------------------------------------
<style type="text/css">
body
{
background: #ff0000 url(/i/eg_bg_03.gif) no-repeat fixed center; //center為xy軸居中顯示
}
</style>
p {background-color: gray; padding: 20px;} //設置p 的背景顏色,四周的邊距各為20px
<style type="text/css">
body{
background-image: url('/i/eg_bg_03.gif');
//有no-repeat與repeat之分,默認的為repeat,自動重復xy軸自動鋪滿,或者:
background-repeat: repeat-y;
y軸橫向鋪滿background-repeat: no-repeat;
//
fixed:
當頁面的其余部分滾動時,背景圖像不會移動。scroll:默認值。背景圖像會隨著頁面其余部分的滾動而移動。inherit:
規定應該從父元素繼承 background-attachment 屬性的設置。background-attachment:fixed;
background-position: 30% 20%;//為x,y軸。 或者50px 100px; 或者:top、bottom、left、right 和 center
}
</style>
------------------------------上述屬性合并為一列----------------------------------------------
<style type="text/css">
body
{
background: #ff0000 url(/i/eg_bg_03.gif) no-repeat fixed center; //center為xy軸居中顯示
}
</style>