2014-03-24 165 views
0

有什麼不對下面的CSS代碼:背景圖像不工作

body { 
    background-image: #000 url(http://www.lifecaredirect.com/images/background-patterns/body-bg-36.jpg) repeat; 
    color: #898989; 
    font-family: 'Roboto', Arial, Verdana; 
    font-weight: 400; 
    -webkit-font-smoothing: antialiased; 
    overflow-x: hidden; 
    font-size:13px; 
    line-height:21px; 
} 

是否嘗試過以下變化也,但仍無法正常工作:

  1. background-image: #000 url("http://www.lifecaredirect.com/images/background-patterns/body-bg-36.jpg") repeat;
  2. background-image: #000 url('http://www.lifecaredirect.com/images/background-patterns/body-bg-36.jpg') repeat;
  3. background-image: url("http://www.lifecaredirect.com/images/background-patterns/body-bg-36.jpg") repeat;
  4. background: url("http://www.lifecaredirect.com/images/background-patterns/body-bg-36.jpg") repeat;
  5. background: url(http://www.lifecaredirect.com/images/background-patterns/body-bg-36.jpg) repeat;

回答

10

The background-image property接受一個參數:的URL的圖像。

您與the background shorthand property,這需要值的列表,並將其應用於各種不同的全屬性(包括background-imagebackground-colorbackground-repeat)混淆了。

+0

,我正想回答,+1你。 –

+0

試過:background-image:url(http://www.lifecaredirect.com/images/background-patterns/body-bg-36.jpg);但仍然沒有成功。 – nik2702

+0

在這裏工作正常:http://jsbin.com/hayuxaji/1/edit?html,output – Quentin

0

拆下#000,重複:)

body { 
background-image: url(http://www.lifecaredirect.com/images/background-patterns/body-bg-36.jpg); 
color: #898989; 
font-family: 'Roboto', Arial, Verdana; 
font-weight: 400; 
-webkit-font-smoothing: antialiased; 
overflow-x: hidden; 
font-size:13px; 
line-height:21px; 
} 

JSFiddle

+0

試過相同但沒有成功:( – nik2702

-1

首先,你需要擺脫重複。並在此之後添加該內容

background-repeat:repeat-y; 

然後確保url在單引號中。

body { 
background-image: #000 url('http://www.lifecaredirect.com/images/background-patterns/body-bg-36.jpg'); 
background-repeat:repeat-y; 
color: #898989; 
font-family: 'Roboto', Arial, Verdana; 
font-weight: 400; 
-webkit-font-smoothing: antialiased; 
overflow-x: hidden; 
font-size:13px; 
line-height:21px; 
} 
1

只能使用background屬性:

body { 
background: #000 url(http://www.lifecaredirect.com/images/background-patterns/body-bg-36.jpg) repeat; 
color: #898989; 
font-family: 'Roboto', Arial, Verdana; 
font-weight: 400; 
-webkit-font-smoothing: antialiased; 
overflow-x: hidden; 
font-size:13px; 
line-height:21px; 
} 

Jsfiddle - example

2

如果你使用的background屬性,你可以使用色彩以及圖像在一起,但如果你使用的背景-image屬性你不能在圖像上使用顏色,你只能使用圖像,而不是你要使用單獨屬性的顏色,如下所示:

body { 
    background-color: #000; 
    background-image: url('http://www.lifecaredirect.com/images/background-patterns/body-bg-36.jpg'); 

} 

或兩者的結合性能在單個後臺財產究竟如下

body { 
    background: #000 url('http://www.lifecaredirect.com/images/background-patterns/body-bg-36.jpg'); 

}