我看到一個CSS代碼,其中有人喜歡背景是什麼:透明url();做?
body { background: transparent url ('background.jpg') repeat scroll;}
什麼是透明的價值呢?我試着googleing這個,但沒有幫助。不會background.jpg只是重寫它?
謝謝。
我看到一個CSS代碼,其中有人喜歡背景是什麼:透明url();做?
body { background: transparent url ('background.jpg') repeat scroll;}
什麼是透明的價值呢?我試着googleing這個,但沒有幫助。不會background.jpg只是重寫它?
謝謝。
transparent
是顏色。元素可以同時具有背景圖像和背景顏色。
以上是等效於:
body {
background-color: transparent;
background-image: url('background.jpg');
background-repeat: repeat;
background-attachment: scroll;
}
顏色是在一般重要的,如果例如背景圖片加載失敗,或者圖片包含透明區域,或者圖片不會重複填充整個區域(這在您的示例中肯定不是這種情況)。
但是,由於transparent
是「初始值」,所以在使用background
簡寫時絕對沒有必要,因爲速記自動將所有未指定的屬性設置爲初始值。
因此,唯一使用情況下transparent
有意義作爲背景顏色包括:
background-color
屬性;一個例子是
body.foo { background-color: blue; }
body.foo.bar { background-color: transparent; }
其實,它不是必需的。
http://www.w3.org/TR/CSS21/colors.html#background
給出一個有效的聲明中,「背景」屬性首先將所有的個人背景屬性爲初始值,然後分配在聲明中給出明確的數值。
由於background-color
的初始值is transparent
,它是隱含設置background:url(...);
時更精確地應用,你的風格規則相當於
background-color: transparent;
background-image: url(...);
background-repeat: repeat;
background-attachment: scroll;
background-position: 0% 0%;
在這兩種情況下
。
然而,許多作者(包括我自己)更明確地設置值
恐怕這是不正確的。顯式設置該值完全沒有區別(請參閱我的答案)。 – user123444555621 2012-04-26 06:39:10
好抓@Pumbaa80,我認爲它是'inherit'。定影。 – Domenic 2012-04-26 06:42:34
@MrLister,我說「修復」,而不是「固定」。 *現在*它是固定的;)。 – Domenic 2012-04-26 06:47:07