2016-06-19 13 views
0

我給背景圖片分配了一個使用css的部分,圖片只顯示在括號內的實時預覽中。這是否應該發生,或者我做錯了什麼。下面的代碼:爲什麼背景圖片只顯示在括號內的實時預覽中

background: url(/img/background.jpeg) center center no-repeat fixed; 
background-size: cover; 
+0

它在哪裏不顯示?路徑是否正確? – m02ph3u5

+0

是的,路徑是正確的。當我打開index.html文件時:// ...它不顯示背景圖片。我必須使用括號的實時預覽功能來顯示背景 –

+0

能夠通過'file:///'打開文件並不意味着您的瀏覽器可以通過http://訪問該文件' – m02ph3u5

回答

0

也許你可以嘗試像這個 -

img { 
border: 1px solid #ddd; 
border-radius: 4px; 
padding: 5px;} 
<img src="example.jpg" alt="example"> 

或者這個 -

body {border-style: groove;border-width: 3px; border-color: Black; 
     width:1300px; padding: 25px; background-color: Aqua; 
    background-image: url("NSIC-logo1.png"); 
     background-repeat:no-repeat;background-position:50% 10% } 
0

我改變了路徑:

background: url(../img/background.jpeg) center center no-repeat fixed; 
background-size: cover; 

把這兩個點爲我工作!