備注:默認(rèn)的圖片背景,如果無設(shè)置,自動(dòng)靠左上角對(duì)齊,如果設(shè)置其位置可以靠background-position定位(值可為像素或者百分比、center),如下
<style type="text/css">
body{
background-image: url('/i/eg_bg_03.gif');
//有no-repeat與repeat之分,默認(rèn)的為repeat,自動(dòng)重復(fù)xy軸自動(dòng)鋪滿,或者:
//
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;} //設(shè)置p 的背景顏色,四周的邊距各為20px
<style type="text/css">
body{
background-image: url('/i/eg_bg_03.gif');
//有no-repeat與repeat之分,默認(rèn)的為repeat,自動(dòng)重復(fù)xy軸自動(dòng)鋪滿,或者:
background-repeat: repeat-y;
y軸橫向鋪滿background-repeat: no-repeat;
//
fixed:
當(dāng)頁面的其余部分滾動(dòng)時(shí),背景圖像不會(huì)移動(dòng)。scroll:默認(rèn)值。背景圖像會(huì)隨著頁面其余部分的滾動(dòng)而移動(dòng)。inherit:
規(guī)定應(yīng)該從父元素繼承 background-attachment 屬性的設(shè)置。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>