css背景固定樣式background-attachment屬性基礎(chǔ)介紹
來源:懂視網(wǎng)
責(zé)編:小OO
時間:2020-11-27 18:52:40
css背景固定樣式background-attachment屬性基礎(chǔ)介紹
一、background-attachment屬性。在CSS中,使用背景附件屬性background-attachment可以設(shè)置背景圖像是隨對象滾動還是固定不動。語法。background-attachment:scroll/fixed。說明。background-attachment 屬性只有2個屬性值。scroll表示背景圖像隨對象滾動而滾動,是默認(rèn)選項;fixed表示背景圖像固定在頁面不動,只有其他的內(nèi)容隨滾動條滾動。舉例。
導(dǎo)讀一、background-attachment屬性。在CSS中,使用背景附件屬性background-attachment可以設(shè)置背景圖像是隨對象滾動還是固定不動。語法。background-attachment:scroll/fixed。說明。background-attachment 屬性只有2個屬性值。scroll表示背景圖像隨對象滾動而滾動,是默認(rèn)選項;fixed表示背景圖像固定在頁面不動,只有其他的內(nèi)容隨滾動條滾動。舉例。
這篇文章主要為大家?guī)韈ss背景固定樣式background-attachment屬性基礎(chǔ)介紹,需要的朋友可以參考下
一、background-attachment屬性
在CSS中,使用背景附件屬性background-attachment可以設(shè)置背景圖像是隨對象滾動還是固定不動。
語法:
background-attachment:scroll/fixed;
說明:
background-attachment 屬性只有2個屬性值。scroll表示背景圖像隨對象滾動而滾動,是默認(rèn)選項;fixed表示背景圖像固定在頁面不動,只有其他的內(nèi)容隨滾動條滾動。
舉例:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
#p1
{
width:160px;
height:1200px;
border:1px solid gray;
background-image:url("cartoongirl.gif");
background-repeat:no-repeat;
background-attachment:fixed;
}
</style>
</head>
<body>
<p id="p1"></p>
</body>
</html>
在瀏覽器預(yù)覽效果如下:

分析:
大家在瀏覽器中拖動右邊的滾動條會發(fā)現(xiàn),背景圖片在頁面固定不動。
在IE或者360中設(shè)置background-attachment之后不能設(shè)置background-position屬性,不然圖片沒辦法在瀏覽器顯示。大家可以測試一下google瀏覽器、Firefox瀏覽器。
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
css背景固定樣式background-attachment屬性基礎(chǔ)介紹
一、background-attachment屬性。在CSS中,使用背景附件屬性background-attachment可以設(shè)置背景圖像是隨對象滾動還是固定不動。語法。background-attachment:scroll/fixed。說明。background-attachment 屬性只有2個屬性值。scroll表示背景圖像隨對象滾動而滾動,是默認(rèn)選項;fixed表示背景圖像固定在頁面不動,只有其他的內(nèi)容隨滾動條滾動。舉例。